2016-11-15 10:56:29 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-03-08 14:16:11 -05:00
|
|
|
class PrecomputeFeedService < BaseService
|
2017-05-19 10:21:52 -04:00
|
|
|
LIMIT = FeedManager::MAX_ITEMS / 4
|
|
|
|
|
|
|
|
def call(account)
|
|
|
|
@account = account
|
|
|
|
populate_feed
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
attr_reader :account
|
|
|
|
|
|
|
|
def populate_feed
|
2017-04-04 07:58:34 -04:00
|
|
|
redis.pipelined do
|
2017-05-19 10:21:52 -04:00
|
|
|
statuses.each do |status|
|
|
|
|
process_status(status)
|
2017-04-04 07:58:34 -04:00
|
|
|
end
|
2016-03-24 21:13:30 -04:00
|
|
|
end
|
2016-03-08 14:16:11 -05:00
|
|
|
end
|
|
|
|
|
2017-05-19 10:21:52 -04:00
|
|
|
def process_status(status)
|
|
|
|
add_status_to_feed(status) unless skip_status?(status)
|
|
|
|
end
|
|
|
|
|
|
|
|
def skip_status?(status)
|
|
|
|
status.direct_visibility? || 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
|
2016-03-08 14:16:11 -05:00
|
|
|
|
|
|
|
def redis
|
2016-11-15 10:56:29 -05:00
|
|
|
Redis.current
|
2016-03-08 14:16:11 -05:00
|
|
|
end
|
|
|
|
end
|