nyastodon/app/services/precompute_feed_service.rb
Akihiko Odaki (@fn_aki@pawoo.net) bab5a18232 Filter direct statuses in Status.as_home_timeline (#3842)
The classes using Status.as_home_timeline, namely Feed and
PrecomputeFeedService are expected to filter direct statuses as
FanOutWriteService does, but their filtering were incomplete or missing.

This commit solves the problem by filtering direct statuses in
as_home_timeline as the other similar methods such as as_public_timeline
does.
2017-06-20 20:41:23 +02:00

48 lines
947 B
Ruby

# frozen_string_literal: true
class PrecomputeFeedService < BaseService
LIMIT = FeedManager::MAX_ITEMS / 4
def call(account)
@account = account
populate_feed
end
private
attr_reader :account
def populate_feed
redis.pipelined do
statuses.each do |status|
process_status(status)
end
redis.del("account:#{@account.id}:regeneration")
end
end
def process_status(status)
add_status_to_feed(status) unless status_filtered?(status)
end
def add_status_to_feed(status)
redis.zadd(account_home_key, status.id, status.reblog? ? status.reblog_of_id : status.id)
end
def status_filtered?(status)
FeedManager.instance.filter?(:home, status, account.id)
end
def account_home_key
FeedManager.instance.key(:home, account.id)
end
def statuses
Status.as_home_timeline(account).order(account_id: :desc).limit(LIMIT)
end
def redis
Redis.current
end
end