2016-11-15 10:56:29 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-03-08 14:16:11 -05:00
|
|
|
class PrecomputeFeedService < BaseService
|
2016-03-24 21:13:30 -04:00
|
|
|
# Fill up a user's home/mentions feed from DB and return a subset
|
2016-03-08 14:16:11 -05:00
|
|
|
# @param [Symbol] type :home or :mentions
|
|
|
|
# @param [Account] account
|
2017-04-02 09:46:31 -04:00
|
|
|
def call(_, account)
|
2017-04-04 07:58:34 -04:00
|
|
|
redis.pipelined do
|
2017-05-10 14:33:32 -04:00
|
|
|
# NOTE: Added `id desc, account_id desc` to `ORDER BY` section to optimize query.
|
|
|
|
Status.as_home_timeline(account).order(account_id: :desc).limit(FeedManager::MAX_ITEMS / 4).each do |status|
|
2017-04-04 13:21:37 -04:00
|
|
|
next if status.direct_visibility? || FeedManager.instance.filter?(:home, status, account.id)
|
2017-04-04 07:58:34 -04:00
|
|
|
redis.zadd(FeedManager.instance.key(:home, account.id), status.id, status.reblog? ? status.reblog_of_id : status.id)
|
|
|
|
end
|
2016-03-24 21:13:30 -04:00
|
|
|
end
|
2016-03-08 14:16:11 -05:00
|
|
|
end
|
|
|
|
|
2016-03-24 21:13:30 -04:00
|
|
|
private
|
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
|