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