feed.rb 815 B

1234567891011121314151617181920212223242526272829303132
  1. # frozen_string_literal: true
  2. class Feed
  3. include Redisable
  4. def initialize(type, id)
  5. @type = type
  6. @id = id
  7. end
  8. def get(limit, max_id = nil, since_id = nil, min_id = nil)
  9. from_redis(limit, max_id, since_id, min_id)
  10. end
  11. protected
  12. def from_redis(limit, max_id, since_id, min_id)
  13. if min_id.blank?
  14. max_id = '+inf' if max_id.blank?
  15. since_id = '-inf' if since_id.blank?
  16. unhydrated = redis.zrevrangebyscore(key, "(#{max_id}", "(#{since_id}", limit: [0, limit], with_scores: true).map(&:first).map(&:to_i)
  17. else
  18. unhydrated = redis.zrangebyscore(key, "(#{min_id}", '+inf', limit: [0, limit], with_scores: true).map(&:first).map(&:to_i)
  19. end
  20. Status.where(id: unhydrated).cache_ids
  21. end
  22. def key
  23. FeedManager.instance.key(@type, @id)
  24. end
  25. end