refactor: use the built-in max/min to simplify the code (#6430)

Signed-off-by: somasoil <somasoil@outlook.com>
This commit is contained in:
somasoil
2026-10-06 00:01:38 +02:00
committed by GitHub
parent 0d989707f8
commit f7a6186731
+1 -4
View File
@@ -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