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.

27 lines
651 B

  1. # frozen_string_literal: true
  2. class Feed
  3. def initialize(type, account)
  4. @type = type
  5. @account = account
  6. end
  7. def get(limit, max_id = nil, since_id = nil)
  8. max_id = '+inf' if max_id.blank?
  9. since_id = '-inf' if since_id.blank?
  10. unhydrated = redis.zrevrangebyscore(key, "(#{max_id}", "(#{since_id}", limit: [0, limit], with_scores: true).map(&:last).map(&:to_i)
  11. status_map = Status.where(id: unhydrated).cache_ids.map { |s| [s.id, s] }.to_h
  12. unhydrated.map { |id| status_map[id] }.compact
  13. end
  14. private
  15. def key
  16. FeedManager.instance.key(@type, @account.id)
  17. end
  18. def redis
  19. Redis.current
  20. end
  21. end