mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-11-25 21:21:36 +01:00
[Glitch] Fix n+1 query in settings migration
Port 0ad2413b35
to glitch-soc
Signed-off-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
parent
75e28731a5
commit
8bf9bd5ac8
1 changed files with 17 additions and 14 deletions
|
@ -31,9 +31,11 @@ class MoveGlitchUserSettings < ActiveRecord::Migration[6.1]
|
|||
end
|
||||
|
||||
def up
|
||||
User.find_each do |user|
|
||||
previous_settings = LegacySetting.where(thing_type: 'User', thing_id: user.id).index_by(&:var)
|
||||
User.find_in_batches do |users|
|
||||
previous_settings_for_batch = LegacySetting.where(thing_type: 'User', thing_id: users.map(&:id)).group_by(&:thing_id)
|
||||
|
||||
users.each do |user|
|
||||
previous_settings = previous_settings_for_batch[user.id]&.index_by(&:var) || {}
|
||||
user_settings = Oj.load(user.settings || '{}')
|
||||
user_settings.delete('theme')
|
||||
|
||||
|
@ -54,6 +56,7 @@ class MoveGlitchUserSettings < ActiveRecord::Migration[6.1]
|
|||
user.update_column('settings', Oj.dump(user_settings)) # rubocop:disable Rails/SkipsModelValidations
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def down; end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue