Skip to content

Commit

Permalink
perf(rate-limit): get pttl only if needed (#2129)
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf committed Aug 10, 2023
1 parent 0d5781a commit 12ce2f3
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/commands/includes/getRateLimitTTL.lua
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
local function getRateLimitTTL(maxJobs, rateLimiterKey)
if maxJobs then
if maxJobs and maxJobs <= tonumber(rcall("GET", rateLimiterKey) or 0) then
local pttl = rcall("PTTL", rateLimiterKey)

if pttl == 0 then
rcall("DEL", rateLimiterKey)
end

local jobCounter = tonumber(rcall("GET", rateLimiterKey) or 0)
if jobCounter >= maxJobs then
if pttl > 0 then
return pttl
end
if pttl > 0 then
return pttl
end
end
return 0
Expand Down

0 comments on commit 12ce2f3

Please sign in to comment.