You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
873 B

  1. # frozen_string_literal: true
  2. class MoveWorker
  3. include Sidekiq::Worker
  4. def perform(source_account_id, target_account_id)
  5. @source_account = Account.find(source_account_id)
  6. @target_account = Account.find(target_account_id)
  7. if @target_account.local?
  8. rewrite_follows!
  9. else
  10. queue_follow_unfollows!
  11. end
  12. rescue ActiveRecord::RecordNotFound
  13. true
  14. end
  15. private
  16. def rewrite_follows!
  17. @source_account.passive_relationships
  18. .where(account: Account.local)
  19. .in_batches
  20. .update_all(target_account: @target_account)
  21. end
  22. def queue_follow_unfollows!
  23. @source_account.followers.local.select(:id).find_in_batches do |accounts|
  24. UnfollowFollowWorker.push_bulk(accounts.map(&:id)) { |follower_id| [follower_id, @source_account.id, @target_account.id] }
  25. end
  26. end
  27. end