Commit d99db00f6a8ddf2c0e23136478a6e6ef7454e819
Committed by
GitHub
1 parent
6ea0c2fd
Exists in
master
and in
5 other branches
Performance improvement for ReindexQueue#reserve when using Redis >=6.2 (#1498)
Redis 6.2 added the ability to specify a count for RPOP. Additionally this changes the behavior of #reserve so that it will not necessarily return a list of unique ids.
Showing
1 changed file
with
20 additions
and
4 deletions
Show diff stats
lib/searchkick/reindex_queue.rb
... | ... | @@ -14,11 +14,17 @@ module Searchkick |
14 | 14 | |
15 | 15 | # TODO use reliable queuing |
16 | 16 | def reserve(limit: 1000) |
17 | - record_ids = Set.new | |
18 | - while record_ids.size < limit && (record_id = Searchkick.with_redis { |r| r.rpop(redis_key) }) | |
19 | - record_ids << record_id | |
17 | + if supports_rpop_with_count? | |
18 | + Searchkick.with_redis { |r| r.call("rpop", redis_key, limit) } | |
19 | + else | |
20 | + record_ids = [] | |
21 | + Searchkick.with_redis do |r| | |
22 | + while record_ids.size < limit && (record_id = r.rpop(redis_key)) | |
23 | + record_ids << record_id | |
24 | + end | |
25 | + end | |
26 | + record_ids | |
20 | 27 | end |
21 | - record_ids.to_a | |
22 | 28 | end |
23 | 29 | |
24 | 30 | def clear |
... | ... | @@ -34,5 +40,15 @@ module Searchkick |
34 | 40 | def redis_key |
35 | 41 | "searchkick:reindex_queue:#{name}" |
36 | 42 | end |
43 | + | |
44 | + def supports_rpop_with_count? | |
45 | + redis_server_version >= Gem::Version.new("6.2") | |
46 | + end | |
47 | + | |
48 | + def redis_server_version | |
49 | + @redis_server_version ||= Searchkick.with_redis { |r| | |
50 | + Gem::Version.new(r.info["server_version"]) | |
51 | + } | |
52 | + end | |
37 | 53 | end |
38 | 54 | end | ... | ... |