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.

30 lines
772 B

  1. class Feed
  2. def initialize(type, account)
  3. @type = type
  4. @account = account
  5. end
  6. def get(limit, max_id = nil)
  7. max_id = '+inf' if max_id.nil?
  8. unhydrated = redis.zrevrangebyscore(key, "(#{max_id}", '-inf', limit: [0, limit])
  9. status_map = Hash.new
  10. # If we're after most recent items and none are there, we need to precompute the feed
  11. if unhydrated.empty? && max_id == '+inf'
  12. PrecomputeFeedService.new.(@type, @account, limit)
  13. else
  14. Status.where(id: unhydrated).with_includes.with_counters.each { |status| status_map[status.id.to_s] = status }
  15. unhydrated.map { |id| status_map[id] }.compact
  16. end
  17. end
  18. private
  19. def key
  20. FeedManager.instance.key(@type, @account.id)
  21. end
  22. def redis
  23. $redis
  24. end
  25. end