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.

37 lines
1.1 KiB

  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? && @source_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. .where.not(account: @target_account.followers.local)
  20. .where.not(account_id: @target_account.id)
  21. .in_batches
  22. .update_all(target_account_id: @target_account.id)
  23. end
  24. def queue_follow_unfollows!
  25. bypass_locked = @target_account.local?
  26. @source_account.followers.local.select(:id).find_in_batches do |accounts|
  27. UnfollowFollowWorker.push_bulk(accounts.map(&:id)) { |follower_id| [follower_id, @source_account.id, @target_account.id, bypass_locked] }
  28. end
  29. end
  30. end