about summary refs log tree commit diff
path: root/app/workers/scheduler/feed_cleanup_scheduler.rb
blob: 42b29f4eca072681ad9ef71b96615fc51c80a709 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true

class Scheduler::FeedCleanupScheduler
  include Sidekiq::Worker
  include Redisable

  sidekiq_options lock: :until_executed, retry: 0

  def perform
    clean_home_feeds!
    clean_list_feeds!
  end

  private

  def clean_home_feeds!
    feed_manager.clean_feeds!(:home, inactive_account_ids)
  end

  def clean_list_feeds!
    feed_manager.clean_feeds!(:list, inactive_list_ids)
  end

  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

  def feed_manager
    FeedManager.instance
  end
end