1
0

unmerge_worker.rb 923 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # frozen_string_literal: true
  2. class UnmergeWorker
  3. include Sidekiq::Worker
  4. include DatabaseHelper
  5. sidekiq_options queue: 'pull'
  6. def perform(from_account_id, into_id, type = 'home')
  7. with_primary do
  8. @from_account = Account.find(from_account_id)
  9. end
  10. case type
  11. when 'home'
  12. unmerge_from_home!(into_id)
  13. when 'list'
  14. unmerge_from_list!(into_id)
  15. end
  16. rescue ActiveRecord::RecordNotFound
  17. true
  18. end
  19. private
  20. def unmerge_from_home!(into_account_id)
  21. with_primary do
  22. @into_account = Account.find(into_account_id)
  23. end
  24. with_read_replica do
  25. FeedManager.instance.unmerge_from_home(@from_account, @into_account)
  26. end
  27. end
  28. def unmerge_from_list!(into_list_id)
  29. with_primary do
  30. @into_list = List.find(into_list_id)
  31. end
  32. with_read_replica do
  33. FeedManager.instance.unmerge_from_list(@from_account, @into_list)
  34. end
  35. end
  36. end