From f7a61867315ff7d3b2cd7347adfc161f32022227 Mon Sep 17 00:00:00 2001 From: somasoil Date: Tue, 6 Oct 2026 00:01:38 +0200 Subject: [PATCH] refactor: use the built-in max/min to simplify the code (#6430) Signed-off-by: somasoil --- internal/ratelimit/ratelimit.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/internal/ratelimit/ratelimit.go b/internal/ratelimit/ratelimit.go index 6862d21c5..09ad21ae3 100644 --- a/internal/ratelimit/ratelimit.go +++ b/internal/ratelimit/ratelimit.go @@ -371,10 +371,7 @@ func (e *entry) retryAfter(rule Rule, now time.Time, cost int) time.Duration { // previous one, has decayed: overlap < (budget + 1) / current. ready = windowEnd.Add(decayTime(rule.Window, e.current, budget+1)) } - wait := ready.Sub(now) - if wait < 0 { - wait = 0 - } + wait := max(ready.Sub(now), 0) // Floor plus one second lands strictly after the boundary even when the // wait is a whole number of seconds, and is never less than one. return time.Duration(math.Floor(wait.Seconds()))*time.Second + time.Second