-
-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add digest scores for faster deletes in sorted sets
- Loading branch information
Showing
13 changed files
with
129 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ class BatchDelete | |
PRIMED | ||
LOCKED | ||
INFO | ||
SCORE | ||
].freeze | ||
|
||
# includes "SidekiqUniqueJobs::Connection" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 24 additions & 6 deletions
30
lib/sidekiq_unique_jobs/lua/shared/_delete_from_sorted_set.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,37 @@ | ||
local function delete_from_sorted_set(name, digest) | ||
local per = 50 | ||
local total = redis.call("zcard", name) | ||
local index = 0 | ||
local offset = 0 | ||
local per = 50 | ||
local total = redis.call("zcard", name) | ||
local score = redis.call("get", digest .. ":SCORE") | ||
local result | ||
|
||
while (index < total) do | ||
local items = redis.call("ZRANGE", name, index, index + per -1) | ||
while (offset < total) do | ||
local items | ||
|
||
if result then | ||
break | ||
end | ||
|
||
if score then | ||
items = redis.call("ZRANGE", name, score, "+inf", "BYSCORE", "LIMIT", offset, per) | ||
else | ||
items = redis.call("ZRANGE", name, offset, offset + per -1) | ||
end | ||
|
||
if #items == 0 then | ||
break | ||
end | ||
|
||
for _, item in pairs(items) do | ||
if string.find(item, digest) then | ||
redis.call("ZREM", name, item) | ||
result = item | ||
break | ||
end | ||
end | ||
index = index + per | ||
|
||
offset = offset + per | ||
end | ||
|
||
return result | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
uniquejobs:changelog | ||
uniquejobs:digests | ||
uniquejobs:expiring_digests | ||
#{digest_one}:SCORE | ||
], | ||
) | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters