8000 [RateLimiter] Fix `RateLimit->getRetryAfter()` return value when consuming `0` or last tokens. by ERuban · Pull Request #52835 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[RateLimiter] Fix RateLimit->getRetryAfter() return value when consuming 0 or last tokens. #52835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Prev Previous commit
Next Next commit
[RateLimit] Allow to get RateLimit without consuming again.
  • Loading branch information
ERuban committed Dec 17, 2023
commit 717b3822d47ace83cd3f5c9bc6c3d8ec492116fd
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function reserve(int $tokens = 1, float $maxTime = null): Reservation
$now = microtime(true);
$hitCount = $window->getHitCount();
$availableTokens = $this->getAvailableTokens($hitCount);
if ($tokens !== 0 && $availableTokens >= $tokens) {
if (0 !== $tokens && $availableTokens >= $tokens) {
$window->add($tokens);

$reservation = new Reservation($now, new RateLimit($this->getAvailableTokens($window->getHitCount()), \DateTimeImmutable::createFromFormat('U', floor($now)), true, $this->limit));
Expand Down
0