Skip to content

Commit 3f51459

Browse files
agibralterdefunkt
authored andcommitted
This version of Job.destroy just uses LREM in the case that arguments are passed. In this case, the whole queue does not need to be passed to the client via LRANGE.
1 parent 2ad409e commit 3f51459

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

lib/resque/job.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,14 @@ def self.destroy(queue, klass, *args)
8080
queue = "queue:#{queue}"
8181
destroyed = 0
8282

83-
redis.lrange(queue, 0, -1).each do |string|
84-
json = decode(string)
85-
86-
match = json['class'] == klass
87-
match &= json['args'] == args unless args.empty?
88-
89-
if match
90-
destroyed += redis.lrem(queue, 0, string).to_i
83+
if args.empty?
84+
redis.lrange(queue, 0, -1).each do |string|
85+
if decode(string)['class'] == klass
86+
destroyed += redis.lrem(queue, 0, string).to_i
87+
end
9188
end
89+
else
90+
destroyed += redis.lrem(queue, 0, encode(:class => klass, :args => args))
9291
end
9392

9493
destroyed

0 commit comments

Comments
 (0)