闭社主体 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.

34 lines
831 B

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