about summary refs log tree commit diff
path: root/app/workers/feed_insert_worker.rb
blob: 65c02d3eff53124ab30bc65bee1132af89a3b29c (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
36
# frozen_string_literal: true

class FeedInsertWorker
  include Sidekiq::Worker

  attr_reader :status, :follower

  def perform(status_id, follower_id)
    @status = Status.find_by(id: status_id)
    @follower = Account.find_by(id: follower_id)

    check_and_insert
  end

  private

  def check_and_insert
    if records_available?
      perform_push unless feed_filtered?
    else
      true
    end
  end

  def records_available?
    status.present? && follower.present?
  end

  def feed_filtered?
    FeedManager.instance.filter?(:home, status, follower.id)
  end

  def perform_push
    FeedManager.instance.push(:home, follower, status)
  end
end