]> cat aescling's git repositories - mastodon.git/blob - app/workers/move_worker.rb
Fix records not being indexed sometimes (#12024)
[mastodon.git] / app / workers / move_worker.rb
1 # frozen_string_literal: true
2
3 class MoveWorker
4 include Sidekiq::Worker
5
6 def perform(source_account_id, target_account_id)
7 @source_account = Account.find(source_account_id)
8 @target_account = Account.find(target_account_id)
9
10 if @target_account.local?
11 rewrite_follows!
12 else
13 queue_follow_unfollows!
14 end
15 rescue ActiveRecord::RecordNotFound
16 true
17 end
18
19 private
20
21 def rewrite_follows!
22 @source_account.passive_relationships
23 .where(account: Account.local)
24 .in_batches
25 .update_all(target_account: @target_account)
26 end
27
28 def queue_follow_unfollows!
29 @source_account.followers.local.select(:id).find_in_batches do |accounts|
30 UnfollowFollowWorker.push_bulk(accounts.map(&:id)) { |follower_id| [follower_id, @source_account.id, @target_account.id] }
31 end
32 end
33 end
This page took 0.08045 seconds and 5 git commands to generate.