perf: Speed up performance of queue.clean when called with a limit #2205
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
I was trying to clean a large queue with millions of entries. Originally, I ran:
But this blocked Redis from saving any other records with the error message:
I switched this to something more like:
But each loop of 100 still took a really long time. Digging into the script, regardless of how many we try to delete, we're listing all the keys on every run of
.clean()
bull/lib/commands/cleanJobsInSet-3.lua
Line 23 in 019d612
Changes
Testing
Tested in production with my queue -- this sped it up a lot! Also ran it on empty queues to make sure that we ended properly
Also added an automated test for some pagination edge cases
Note for reviewers
It's a lot easier to see changes with "Hide whitespace changes" turned on: https:/OptimalBits/bull/pull/2205/files?diff=split&w=1