Change Move handler to also move list memberships (#24808)

This commit is contained in:
Claire 2023-05-03 14:03:38 +02:00 committed by GitHub
parent 9a52a7f7a0
commit c98b012583
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 16 deletions

View file

@ -9,10 +9,10 @@ class FollowMigrationService < FollowService
def call(source_account, target_account, old_target_account, bypass_locked: false)
@old_target_account = old_target_account
follow = source_account.active_relationships.find_by(target_account: old_target_account)
reblogs = follow&.show_reblogs?
notify = follow&.notify?
languages = follow&.languages
@original_follow = source_account.active_relationships.find_by(target_account: old_target_account)
reblogs = @original_follow&.show_reblogs?
notify = @original_follow&.notify?
languages = @original_follow&.languages
super(source_account, target_account, reblogs: reblogs, notify: notify, languages: languages, bypass_locked: bypass_locked, bypass_limit: true)
end
@ -21,6 +21,7 @@ class FollowMigrationService < FollowService
def request_follow!
follow_request = @source_account.request_follow!(@target_account, **follow_options.merge(rate_limit: @options[:with_rate_limit], bypass_limit: @options[:bypass_limit]))
migrate_list_accounts!
if @target_account.local?
LocalNotificationWorker.perform_async(@target_account.id, follow_request.id, follow_request.class.name, 'follow_request')
@ -34,7 +35,16 @@ class FollowMigrationService < FollowService
def direct_follow!
follow = super
migrate_list_accounts!
UnfollowService.new.call(@source_account, @old_target_account, skip_unmerge: true)
follow
end
def migrate_list_accounts!
ListAccount.where(follow_id: @original_follow.id).includes(:list).find_each do |list_account|
list_account.list.accounts << @target_account
end
end
end

View file

@ -8,9 +8,9 @@ class MoveWorker
@target_account = Account.find(target_account_id)
if @target_account.local? && @source_account.local?
nb_moved = rewrite_follows!
@source_account.update_count!(:followers_count, -nb_moved)
@target_account.update_count!(:followers_count, nb_moved)
num_moved = rewrite_follows!
@source_account.update_count!(:followers_count, -num_moved)
@target_account.update_count!(:followers_count, num_moved)
else
queue_follow_unfollows!
end
@ -29,12 +29,18 @@ class MoveWorker
private
def rewrite_follows!
num_moved = 0
@source_account.passive_relationships
.where(account: Account.local)
.where.not(account: @target_account.followers.local)
.where.not(account_id: @target_account.id)
.in_batches
.update_all(target_account_id: @target_account.id)
.in_batches do |follows|
ListAccount.where(follow: follows).in_batches.update_all(account_id: @target_account.id)
num_moved += follows.update_all(target_account_id: @target_account.id)
end
num_moved
end
def queue_follow_unfollows!