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

Do not perform redundant job look-up on delete for SortedEntry

* Seperate SortedEntry delete into delete_by_jid and delete_by_score
 * delete_by_score can now take a time range
 * use @_size -= ret instead of zcard
This commit is contained in:
pik 2015-08-03 02:57:57 +08:00
parent 677c1bfe5d
commit f378074b84

View file

@ -369,11 +369,17 @@ module Sidekiq
end end
def delete def delete
@parent.delete(score, jid) if @value
@parent.delete_by_value(@parent.name, @value)
elsif jid
@parent.delete_by_jid(score, jid)
else
@parent.delete_by_score(score, score)
end
end end
def reschedule(at) def reschedule(at)
@parent.delete(score, jid) delete
@parent.schedule(at, item) @parent.schedule(at, item)
end end
@ -520,35 +526,41 @@ module Sidekiq
end end
def delete(score, jid = nil) def delete(score, jid = nil)
if jid jid ? delete_by_jid(score, jid) : delete_by_score(score, score)
elements = Sidekiq.redis do |conn| end
conn.zrangebyscore(name, score, score)
end
elements_with_jid = elements.map do |element| def delete_by_value(name, value)
message = Sidekiq.load_json(element) Sidekiq.redis do |conn|
ret = conn.zrem(name, value)
if message["jid"] == jid @_size -= 1 if ret
_, @_size = Sidekiq.redis do |conn| ret
conn.multi do
conn.zrem(name, element)
conn.zcard name
end
end
end
end
elements_with_jid.count != 0
else
count, @_size = Sidekiq.redis do |conn|
conn.multi do
conn.zremrangebyscore(name, score, score)
conn.zcard name
end
end
count != 0
end end
end end
def delete_by_jid(score, jid)
elements = Sidekiq.redis do |conn|
conn.zrangebyscore(name, score, score)
end
elements.each do |element|
message = Sidekiq.load_json(element)
if message["jid"] == jid
break Sidekiq.redis do |conn|
ret = conn.zrem(name, element)
@_size -= 1 if ret
ret
end
end
false
end
end
def delete_by_score(score_min, score_max)
Sidekiq.redis do |conn|
ret = conn.zremrangebyscore(name, score_min, score_max)
@_size -= ret
ret
end
end
end end
## ##