2020-11-23 17:50:16 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module AccountMerging
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
def merge_with!(other_account)
|
|
|
|
# Since it's the same remote resource, the remote resource likely
|
|
|
|
# already believes we are following/blocking, so it's safe to
|
|
|
|
# re-attribute the relationships too. However, during the presence
|
|
|
|
# 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
|
|
|
|
|
|
|
|
owned_classes = [
|
|
|
|
Status, StatusPin, MediaAttachment, Poll, Report, Tombstone, Favourite,
|
|
|
|
Follow, FollowRequest, Block, Mute, AccountIdentityProof,
|
|
|
|
AccountModerationNote, AccountPin, AccountStat, ListAccount,
|
2021-05-12 23:19:44 +02:00
|
|
|
PollVote, Mention, AccountDeletionRequest, AccountNote, FollowRecommendationSuppression
|
2020-11-23 17:50:16 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
owned_classes.each do |klass|
|
|
|
|
klass.where(account_id: other_account.id).find_each do |record|
|
|
|
|
begin
|
|
|
|
record.update_attribute(:account_id, id)
|
|
|
|
rescue ActiveRecord::RecordNotUnique
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-12-04 02:23:51 +01:00
|
|
|
target_classes = [
|
|
|
|
Follow, FollowRequest, Block, Mute, AccountModerationNote, AccountPin,
|
|
|
|
AccountNote
|
|
|
|
]
|
2020-11-23 17:50:16 +01:00
|
|
|
|
|
|
|
target_classes.each do |klass|
|
|
|
|
klass.where(target_account_id: other_account.id).find_each do |record|
|
|
|
|
begin
|
|
|
|
record.update_attribute(:target_account_id, id)
|
|
|
|
rescue ActiveRecord::RecordNotUnique
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-12-02 21:20:00 +01:00
|
|
|
|
2021-05-12 23:19:44 +02:00
|
|
|
CanonicalEmailBlock.where(reference_account_id: other_account.id).find_each do |record|
|
|
|
|
record.update_attribute(:reference_account_id, id)
|
|
|
|
end
|
|
|
|
|
2020-12-02 21:20:00 +01:00
|
|
|
# Some follow relationships have moved, so the cache is stale
|
|
|
|
Rails.cache.delete_matched("followers_hash:#{id}:*")
|
|
|
|
Rails.cache.delete_matched("relationships:#{id}:*")
|
|
|
|
Rails.cache.delete_matched("relationships:*:#{id}")
|
2020-11-23 17:50:16 +01:00
|
|
|
end
|
|
|
|
end
|