diff options
author | David Yip <yipdw@member.fsf.org> | 2018-06-02 16:15:36 -0500 |
---|---|---|
committer | David Yip <yipdw@member.fsf.org> | 2018-06-02 16:15:36 -0500 |
commit | 3550470c18425e80a322e6fe56245c9ede3d0689 (patch) | |
tree | 10c7539e0bf80a9a5d20aa2c8acf227803d3789b /db/migrate | |
parent | a641d1b5b8e9f20104ab16e5419e6dee4e5af37f (diff) | |
parent | 00512ecf87e1098f5632eeec2cd116344a787523 (diff) |
Merge remote-tracking branch 'origin/master' into gs-master
Conflicts: app/javascript/mastodon/locales/en.json app/javascript/mastodon/locales/ja.json app/javascript/mastodon/locales/pl.json The above conflicts appear to be a text conflict introduced by glitch-soc's additional level of columns (i.e. moving a bunch of columns under the Misc option). They were resolved via accept-ours.
Diffstat (limited to 'db/migrate')
-rw-r--r-- | db/migrate/20180528141303_fix_accounts_unique_index.rb | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/db/migrate/20180528141303_fix_accounts_unique_index.rb b/db/migrate/20180528141303_fix_accounts_unique_index.rb index aadb5b7db..96cee37f9 100644 --- a/db/migrate/20180528141303_fix_accounts_unique_index.rb +++ b/db/migrate/20180528141303_fix_accounts_unique_index.rb @@ -39,26 +39,28 @@ class FixAccountsUniqueIndex < ActiveRecord::Migration[5.2] accounts = accounts.first.local? ? accounts.sort_by(&:created_at) : accounts.sort_by(&:updated_at).reverse reference_account = accounts.shift - accounts.each do |other_account| - if other_account.public_key == reference_account.public_key - # The accounts definitely point to the same resource, so - # it's safe to re-attribute content and relationships - merge_accounts!(reference_account, other_account) - elsif other_account.local? - # Since domain is in the GROUP BY clause, both accounts - # are always either going to be local or not local, so only - # one check is needed. Since we cannot support two users with - # the same username locally, one has to go. 😢 - other_account.user&.destroy - end + say_with_time "Deduplicating @#{reference_account.acct} (#{accounts.size} duplicates)..." do + accounts.each do |other_account| + if other_account.public_key == reference_account.public_key + # The accounts definitely point to the same resource, so + # it's safe to re-attribute content and relationships + merge_accounts!(reference_account, other_account) + elsif other_account.local? + # Since domain is in the GROUP BY clause, both accounts + # are always either going to be local or not local, so only + # one check is needed. Since we cannot support two users with + # the same username locally, one has to go. 😢 + other_account.user&.destroy + end - other_account.destroy + other_account.destroy + end end end def merge_accounts!(main_account, duplicate_account) - [Status, Favourite, Mention, StatusPin, StreamEntry].each do |klass| - klass.where(account_id: duplicate_account.id).update_all(account_id: main_account.id) + [Status, Mention, StatusPin, StreamEntry].each do |klass| + klass.where(account_id: duplicate_account.id).in_batches.update_all(account_id: main_account.id) end # Since it's the same remote resource, the remote resource likely @@ -67,18 +69,20 @@ class FixAccountsUniqueIndex < ActiveRecord::Migration[5.2] # of the index bug users could have *also* followed the reference # account already, therefore mass update will not work and we need # to check for (and skip past) uniqueness errors - [Follow, FollowRequest, Block, Mute].each do |klass| + [Favourite, Follow, FollowRequest, Block, Mute].each do |klass| klass.where(account_id: duplicate_account.id).find_each do |record| begin - record.update(account_id: main_account.id) + record.update_attribute(:account_id, main_account.id) rescue ActiveRecord::RecordNotUnique next end end + end + [Follow, FollowRequest, Block, Mute].each do |klass| klass.where(target_account_id: duplicate_account.id).find_each do |record| begin - record.update(target_account_id: main_account.id) + record.update_attribute(:target_account_id, main_account.id) rescue ActiveRecord::RecordNotUnique next end |