mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-14 02:44:13 +00:00
cc9a6a710f
* Spec for feed insert worker when missing records * more specs! * Refactor feed insert worker
37 lines
657 B
Ruby
37 lines
657 B
Ruby
# 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
|