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:
parent
677c1bfe5d
commit
f378074b84
1 changed files with 39 additions and 27 deletions
|
@ -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)
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete_by_value(name, value)
|
||||||
|
Sidekiq.redis do |conn|
|
||||||
|
ret = conn.zrem(name, value)
|
||||||
|
@_size -= 1 if ret
|
||||||
|
ret
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete_by_jid(score, jid)
|
||||||
elements = Sidekiq.redis do |conn|
|
elements = Sidekiq.redis do |conn|
|
||||||
conn.zrangebyscore(name, score, score)
|
conn.zrangebyscore(name, score, score)
|
||||||
end
|
end
|
||||||
|
elements.each do |element|
|
||||||
elements_with_jid = elements.map do |element|
|
|
||||||
message = Sidekiq.load_json(element)
|
message = Sidekiq.load_json(element)
|
||||||
|
|
||||||
if message["jid"] == jid
|
if message["jid"] == jid
|
||||||
_, @_size = Sidekiq.redis do |conn|
|
break Sidekiq.redis do |conn|
|
||||||
conn.multi do
|
ret = conn.zrem(name, element)
|
||||||
conn.zrem(name, element)
|
@_size -= 1 if ret
|
||||||
conn.zcard name
|
ret
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
false
|
||||||
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_score(score_min, score_max)
|
||||||
|
Sidekiq.redis do |conn|
|
||||||
|
ret = conn.zremrangebyscore(name, score_min, score_max)
|
||||||
|
@_size -= ret
|
||||||
|
ret
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
Loading…
Reference in a new issue