2016-03-08 11:16:11 -08:00
|
|
|
class PrecomputeFeedService < BaseService
|
2016-03-24 18:13:30 -07:00
|
|
|
# Fill up a user's home/mentions feed from DB and return a subset
|
2016-03-08 11:16:11 -08:00
|
|
|
# @param [Symbol] type :home or :mentions
|
|
|
|
# @param [Account] account
|
|
|
|
# @return [Array]
|
2016-03-24 18:13:30 -07:00
|
|
|
def call(type, account, limit)
|
|
|
|
instant_return = []
|
2016-03-08 11:16:11 -08:00
|
|
|
|
2016-03-24 18:13:30 -07:00
|
|
|
Status.send("as_#{type}_timeline", account).order('created_at desc').limit(FeedManager::MAX_ITEMS).each do |status|
|
2016-09-09 11:04:34 -07:00
|
|
|
next if type == :home && FeedManager.instance.filter_status?(status, account)
|
|
|
|
redis.zadd(FeedManager.instance.key(type, account.id), status.id, status.id)
|
2016-03-24 18:13:30 -07:00
|
|
|
instant_return << status unless instant_return.size > limit
|
|
|
|
end
|
2016-03-08 11:16:11 -08:00
|
|
|
|
2016-03-24 18:13:30 -07:00
|
|
|
instant_return
|
2016-03-08 11:16:11 -08:00
|
|
|
end
|
|
|
|
|
2016-03-24 18:13:30 -07:00
|
|
|
private
|
2016-03-08 11:16:11 -08:00
|
|
|
|
|
|
|
def redis
|
|
|
|
$redis
|
|
|
|
end
|
|
|
|
end
|