1
0
mirror of https://github.com/funamitech/mastodon synced 2024-12-15 07:09:03 +09:00

Fix n+1 query for move emoji reaction settings migration

This commit is contained in:
Jeremy Kescher 2023-05-10 00:00:06 +02:00
parent c781b34278
commit 224ced2cc0
No known key found for this signature in database
GPG Key ID: 80A419A7A613DFA4

View File

@ -20,9 +20,11 @@ class MoveEmojiReactionSettings < ActiveRecord::Migration[6.1]
end end
def up def up
User.find_each do |user| User.find_in_batches do |users|
previous_settings = LegacySetting.where(thing_type: 'User', thing_id: user.id).index_by(&:var) 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 = Oj.load(user.settings || '{}')
user_settings.delete('theme') user_settings.delete('theme')
@ -43,6 +45,5 @@ class MoveEmojiReactionSettings < ActiveRecord::Migration[6.1]
user.update_column('settings', Oj.dump(user_settings)) # rubocop:disable Rails/SkipsModelValidations user.update_column('settings', Oj.dump(user_settings)) # rubocop:disable Rails/SkipsModelValidations
end end
end end
end
def down; end
end end