1
0
mirror of https://github.com/mastodon/mastodon synced 2024-11-24 23:26:22 +09:00
mastodon/app/services/precompute_feed_service.rb
2017-07-11 01:00:01 +02:00

44 lines
908 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
pairs = statuses.reverse_each.lazy.reject(&method(:status_filtered?)).map(&method(:process_status)).to_a
redis.pipelined do
redis.zadd(account_home_key, pairs) if pairs.any?
redis.del("account:#{@account.id}:regeneration")
end
end
def process_status(status)
[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