闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
680 B

  1. class PrecomputeFeedService < BaseService
  2. # Fill up a user's home/mentions feed from DB and return a subset
  3. # @param [Symbol] type :home or :mentions
  4. # @param [Account] account
  5. # @return [Array]
  6. def call(type, account, limit)
  7. instant_return = []
  8. Status.send("as_#{type}_timeline", account).order('created_at desc').limit(FeedManager::MAX_ITEMS).find_each do |status|
  9. next if FeedManager.instance.filter?(type, status, account)
  10. redis.zadd(FeedManager.instance.key(type, account.id), status.id, status.id)
  11. instant_return << status unless instant_return.size > limit
  12. end
  13. instant_return
  14. end
  15. private
  16. def redis
  17. $redis
  18. end
  19. end