2016-11-16 02:56:29 +11:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-03-09 06:16:11 +11:00
|
|
|
class PrecomputeFeedService < BaseService
|
2017-05-20 00:21:52 +10:00
|
|
|
LIMIT = FeedManager::MAX_ITEMS / 4
|
|
|
|
|
|
|
|
def call(account)
|
|
|
|
@account = account
|
|
|
|
populate_feed
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
attr_reader :account
|
|
|
|
|
|
|
|
def populate_feed
|
2017-06-29 09:25:31 +10:00
|
|
|
pairs = statuses.reverse_each.map(&method(:process_status))
|
2017-06-14 21:37:03 +10:00
|
|
|
|
2017-06-29 09:25:31 +10:00
|
|
|
redis.pipelined do
|
2017-06-30 21:39:42 +10:00
|
|
|
redis.zadd(account_home_key, pairs) if pairs.any?
|
2017-06-14 21:37:03 +10:00
|
|
|
redis.del("account:#{@account.id}:regeneration")
|
2016-03-25 12:13:30 +11:00
|
|
|
end
|
2016-03-09 06:16:11 +11:00
|
|
|
end
|
|
|
|
|
2017-05-20 00:21:52 +10:00
|
|
|
def process_status(status)
|
2017-06-29 09:25:31 +10:00
|
|
|
[status.id, status.reblog? ? status.reblog_of_id : status.id] unless status_filtered?(status)
|
2017-05-20 00:21:52 +10:00
|
|
|
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-09 06:16:11 +11:00
|
|
|
|
|
|
|
def redis
|
2016-11-16 02:56:29 +11:00
|
|
|
Redis.current
|
2016-03-09 06:16:11 +11:00
|
|
|
end
|
|
|
|
end
|