1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

Speedup iterating over WorkSet (#5559)

This commit is contained in:
fatkodima 2022-10-04 00:51:35 +03:00 committed by GitHub
parent d424e45328
commit 7037533e8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1103,15 +1103,23 @@ module Sidekiq
def each(&block)
results = []
procs = nil
all_works = nil
Sidekiq.redis do |conn|
procs = conn.sscan_each("processes").to_a
procs.sort.each do |key|
valid, workers = conn.pipelined { |pipeline|
pipeline.exists?(key)
procs = conn.sscan_each("processes").to_a.sort
all_works = conn.pipelined do |pipeline|
procs.each do |key|
pipeline.hgetall("#{key}:work")
}
next unless valid
end
end
end
procs.zip(all_works).each do |key, workers|
workers.each_pair do |tid, json|
next if json.empty?
hsh = Sidekiq.load_json(json)
p = hsh["payload"]
# avoid breaking API, this is a side effect of the JSON optimization in #4316
@ -1119,7 +1127,6 @@ module Sidekiq
results << [key, tid, hsh]
end
end
end
results.sort_by { |(_, _, hsh)| hsh["run_at"] }.each(&block)
end