1
0

merge_worker.rb 962 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # frozen_string_literal: true
  2. class MergeWorker
  3. include Sidekiq::Worker
  4. include Redisable
  5. include DatabaseHelper
  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. merge_into_home!(into_id)
  13. when 'list'
  14. merge_into_list!(into_id)
  15. end
  16. rescue ActiveRecord::RecordNotFound
  17. true
  18. end
  19. private
  20. def merge_into_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.merge_into_home(@from_account, @into_account)
  26. end
  27. ensure
  28. redis.del("account:#{into_account_id}:regeneration")
  29. end
  30. def merge_into_list!(into_list_id)
  31. with_primary do
  32. @into_list = List.find(into_list_id)
  33. end
  34. with_read_replica do
  35. FeedManager.instance.merge_into_list(@from_account, @into_list)
  36. end
  37. end
  38. end