闭社主体 forked from https://github.com/tootsuite/mastodon
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.

62 lines
1.4 KiB

  1. # frozen_string_literal: true
  2. class Scheduler::FeedCleanupScheduler
  3. include Sidekiq::Worker
  4. def perform
  5. clean_home_feeds!
  6. clean_list_feeds!
  7. end
  8. private
  9. def clean_home_feeds!
  10. clean_feeds!(inactive_account_ids, :home)
  11. end
  12. def clean_list_feeds!
  13. clean_feeds!(inactive_list_ids, :list)
  14. end
  15. def clean_feeds!(ids, type)
  16. reblogged_id_sets = {}
  17. redis.pipelined do
  18. ids.each do |feed_id|
  19. redis.del(feed_manager.key(type, feed_id))
  20. reblog_key = feed_manager.key(type, feed_id, 'reblogs')
  21. # We collect a future for this: we don't block while getting
  22. # it, but we can iterate over it later.
  23. reblogged_id_sets[feed_id] = redis.zrange(reblog_key, 0, -1)
  24. redis.del(reblog_key)
  25. end
  26. end
  27. # Remove all of the reblog tracking keys we just removed the
  28. # references to.
  29. redis.pipelined do
  30. reblogged_id_sets.each do |feed_id, future|
  31. future.value.each do |reblogged_id|
  32. reblog_set_key = feed_manager.key(type, feed_id, "reblogs:#{reblogged_id}")
  33. redis.del(reblog_set_key)
  34. end
  35. end
  36. end
  37. end
  38. def inactive_account_ids
  39. @inactive_account_ids ||= User.confirmed.inactive.pluck(:account_id)
  40. end
  41. def inactive_list_ids
  42. List.where(account_id: inactive_account_ids).pluck(:id)
  43. end
  44. def feed_manager
  45. FeedManager.instance
  46. end
  47. def redis
  48. Redis.current
  49. end
  50. end