0
0
Fork 0

Fix various edge cases with local moves (#24812)

This commit is contained in:
Claire 2023-05-03 19:19:25 +02:00 committed by GitHub
parent 1e75eb690d
commit a2a22bad23
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 108 additions and 32 deletions

View file

@ -31,6 +31,32 @@ class MoveWorker
def rewrite_follows!
num_moved = 0
# First, approve pending follow requests for the new account,
# this allows correctly processing list memberships with pending
# follow requests
FollowRequest.where(account: @source_account.followers, target_account_id: @target_account.id).find_each do |follow_request|
ListAccount.where(follow_id: follow_request.id).includes(:list).find_each do |list_account|
list_account.list.accounts << @target_account
rescue ActiveRecord::RecordInvalid
nil
end
follow_request.authorize!
end
# Then handle accounts that follow both the old and new account
@source_account.passive_relationships
.where(account: Account.local)
.where(account: @target_account.followers.local)
.in_batches do |follows|
ListAccount.where(follow: follows).includes(:list).find_each do |list_account|
list_account.list.accounts << @target_account
rescue ActiveRecord::RecordInvalid
nil
end
end
# Finally, handle the common case of accounts not following the new account
@source_account.passive_relationships
.where(account: Account.local)
.where.not(account: @target_account.followers.local)