]> cat aescling's git repositories - mastodon.git/blob - app/models/feed.rb
Fix batch order warnings in BatchedRemoveStatusService (#15409)
[mastodon.git] / app / models / feed.rb
1 # frozen_string_literal: true
2
3 class Feed
4 include Redisable
5
6 def initialize(type, id)
7 @type = type
8 @id = id
9 end
10
11 def get(limit, max_id = nil, since_id = nil, min_id = nil)
12 limit = limit.to_i
13 max_id = max_id.to_i if max_id.present?
14 since_id = since_id.to_i if since_id.present?
15 min_id = min_id.to_i if min_id.present?
16
17 from_redis(limit, max_id, since_id, min_id)
18 end
19
20 protected
21
22 def from_redis(limit, max_id, since_id, min_id)
23 max_id = '+inf' if max_id.blank?
24 if min_id.blank?
25 since_id = '-inf' if since_id.blank?
26 unhydrated = redis.zrevrangebyscore(key, "(#{max_id}", "(#{since_id}", limit: [0, limit], with_scores: true).map(&:first).map(&:to_i)
27 else
28 unhydrated = redis.zrangebyscore(key, "(#{min_id}", "(#{max_id}", limit: [0, limit], with_scores: true).map(&:first).map(&:to_i)
29 end
30
31 Status.where(id: unhydrated).cache_ids
32 end
33
34 def key
35 FeedManager.instance.key(@type, @id)
36 end
37 end
This page took 0.160255 seconds and 6 git commands to generate.