2017-05-20 10:42:58 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'sidekiq-scheduler'
|
|
|
|
|
|
|
|
class Scheduler::FeedCleanupScheduler
|
|
|
|
include Sidekiq::Worker
|
|
|
|
|
|
|
|
def perform
|
2017-10-17 02:45:06 -07:00
|
|
|
reblogged_id_sets = {}
|
|
|
|
feedmanager = FeedManager.instance
|
|
|
|
|
|
|
|
redis.pipelined do
|
|
|
|
inactive_user_ids.each do |account_id|
|
|
|
|
redis.del(feedmanager.key(:home, account_id))
|
|
|
|
reblog_key = feedmanager.key(:home, account_id, 'reblogs')
|
|
|
|
# We collect a future for this: we don't block while getting
|
|
|
|
# it, but we can iterate over it later.
|
|
|
|
reblogged_id_sets[account_id] = redis.zrange(reblog_key, 0, -1)
|
|
|
|
redis.del(reblog_key)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Remove all of the reblog tracking keys we just removed the
|
|
|
|
# references to.
|
2017-05-20 10:42:58 -07:00
|
|
|
redis.pipelined do
|
2017-10-17 02:45:06 -07:00
|
|
|
reblogged_id_sets.each do |account_id, future|
|
|
|
|
future.value.each do |reblogged_id|
|
|
|
|
reblog_set_key = feedmanager.key(:home, account_id, "reblogs:#{reblogged_id}")
|
|
|
|
redis.del(reblog_set_key)
|
|
|
|
end
|
2017-05-20 10:42:58 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-10-17 02:45:06 -07:00
|
|
|
def inactive_user_ids
|
|
|
|
@inactive_user_ids ||= User.confirmed.inactive.pluck(:account_id)
|
2017-05-20 10:42:58 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def redis
|
|
|
|
Redis.current
|
|
|
|
end
|
|
|
|
end
|