mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2024-11-14 11:37:06 +08:00
a3b3387f01
* Purge from dailies * Fix * Migrate logic to lua script * added test to pass coverage * typo * also purging user from daily lbs on personal bests clear Co-authored-by: Miodec <jack@monkeytype.com>
23 lines
667 B
Lua
23 lines
667 B
Lua
local redis_call = redis.call
|
|
local string_match = string.match
|
|
|
|
local user_id = ARGV[1]
|
|
local leaderboards_namespace = ARGV[2]
|
|
|
|
local current_cursor = '0'
|
|
local match_pattern = leaderboards_namespace .. '*'
|
|
|
|
repeat
|
|
local result = redis_call('SCAN', current_cursor, 'MATCH', match_pattern)
|
|
local next_cursor, matched_keys = result[1], result[2]
|
|
|
|
for _, key in ipairs(matched_keys) do
|
|
if (string_match(key, 'results')) then
|
|
redis_call('HDEL', key, user_id)
|
|
elseif (string_match(key, 'scores')) then
|
|
redis_call('ZREM', key, user_id)
|
|
end
|
|
end
|
|
|
|
current_cursor = next_cursor
|
|
until (current_cursor == '0')
|