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.

43 lines
1.1 KiB

  1. # frozen_string_literal: true
  2. require 'sidekiq-scheduler'
  3. class Scheduler::FeedCleanupScheduler
  4. include Sidekiq::Worker
  5. def perform
  6. reblogged_id_sets = {}
  7. feedmanager = FeedManager.instance
  8. redis.pipelined do
  9. inactive_user_ids.each do |account_id|
  10. redis.del(feedmanager.key(:home, account_id))
  11. reblog_key = feedmanager.key(:home, account_id, 'reblogs')
  12. # We collect a future for this: we don't block while getting
  13. # it, but we can iterate over it later.
  14. reblogged_id_sets[account_id] = redis.zrange(reblog_key, 0, -1)
  15. redis.del(reblog_key)
  16. end
  17. end
  18. # Remove all of the reblog tracking keys we just removed the
  19. # references to.
  20. redis.pipelined do
  21. reblogged_id_sets.each do |account_id, future|
  22. future.value.each do |reblogged_id|
  23. reblog_set_key = feedmanager.key(:home, account_id, "reblogs:#{reblogged_id}")
  24. redis.del(reblog_set_key)
  25. end
  26. end
  27. end
  28. end
  29. private
  30. def inactive_user_ids
  31. @inactive_user_ids ||= User.confirmed.inactive.pluck(:account_id)
  32. end
  33. def redis
  34. Redis.current
  35. end
  36. end