2017-05-20 10:42:58 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Scheduler::FeedCleanupScheduler
|
|
|
|
include Sidekiq::Worker
|
2019-02-02 10:11:38 -08:00
|
|
|
include Redisable
|
2017-05-20 10:42:58 -07:00
|
|
|
|
2018-08-25 04:28:07 -07:00
|
|
|
sidekiq_options unique: :until_executed, retry: 0
|
2018-08-19 06:48:29 -07:00
|
|
|
|
2017-05-20 10:42:58 -07:00
|
|
|
def perform
|
2017-12-05 14:20:27 -08:00
|
|
|
clean_home_feeds!
|
|
|
|
clean_list_feeds!
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def clean_home_feeds!
|
|
|
|
clean_feeds!(inactive_account_ids, :home)
|
|
|
|
end
|
|
|
|
|
|
|
|
def clean_list_feeds!
|
|
|
|
clean_feeds!(inactive_list_ids, :list)
|
|
|
|
end
|
|
|
|
|
|
|
|
def clean_feeds!(ids, type)
|
2017-10-17 02:45:06 -07:00
|
|
|
reblogged_id_sets = {}
|
|
|
|
|
|
|
|
redis.pipelined do
|
2017-12-05 14:20:27 -08:00
|
|
|
ids.each do |feed_id|
|
|
|
|
redis.del(feed_manager.key(type, feed_id))
|
|
|
|
reblog_key = feed_manager.key(type, feed_id, 'reblogs')
|
2017-10-17 02:45:06 -07:00
|
|
|
# We collect a future for this: we don't block while getting
|
|
|
|
# it, but we can iterate over it later.
|
2017-12-05 14:20:27 -08:00
|
|
|
reblogged_id_sets[feed_id] = redis.zrange(reblog_key, 0, -1)
|
2017-10-17 02:45:06 -07:00
|
|
|
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-12-05 14:20:27 -08:00
|
|
|
reblogged_id_sets.each do |feed_id, future|
|
2017-10-17 02:45:06 -07:00
|
|
|
future.value.each do |reblogged_id|
|
2017-12-05 14:20:27 -08:00
|
|
|
reblog_set_key = feed_manager.key(type, feed_id, "reblogs:#{reblogged_id}")
|
2017-10-17 02:45:06 -07:00
|
|
|
redis.del(reblog_set_key)
|
|
|
|
end
|
2017-05-20 10:42:58 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-12-05 14:20:27 -08:00
|
|
|
def inactive_account_ids
|
|
|
|
@inactive_account_ids ||= User.confirmed.inactive.pluck(:account_id)
|
|
|
|
end
|
|
|
|
|
|
|
|
def inactive_list_ids
|
|
|
|
List.where(account_id: inactive_account_ids).pluck(:id)
|
|
|
|
end
|
2017-05-20 10:42:58 -07:00
|
|
|
|
2017-12-05 14:20:27 -08:00
|
|
|
def feed_manager
|
|
|
|
FeedManager.instance
|
2017-05-20 10:42:58 -07:00
|
|
|
end
|
|
|
|
end
|