8000 [RateLimiter][Security] Improve performance of login/request rate limiter by Seldaek · Pull Request #46110 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Allow consuming 0 tokens to peek at the token storage
  • Loading branch information
Seldaek authored and wouterj committed Jul 24, 2022
commit a029188317314bac4cb8be6a1f74e4f400ae58f3
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ public function reserve(int $tokens = 1, float $maxTime = null): Reservation

$reservation = new Reservation($now + $waitDuration, new RateLimit($window->getAvailableTokens($now), \DateTimeImmutable::createFromFormat('U', floor($now + $waitDuration)), false, $this->limit));
}
$this->storage->save($window);

if (0 < $tokens) {
$this->storage->save($window);
}
} finally {
$this->lock->release();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ public function consume(int $tokens = 1): RateLimit
}

$window->add($tokens);
$this->storage->save($window);

if (0 < $tokens) {
$this->storage->save($window);
}

return new RateLimit($this->getAvailableTokens($window->getHitCount()), $window->getRetryAfter(), true, $this->limit);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ public function reserve(int $tokens = 1, float $maxTime = null): Reservation
$reservation = new Reservation($now + $waitDuration, new RateLimit(0, \DateTimeImmutable::createFromFormat('U', floor($now + $waitDuration)), false, $this->maxBurst));
}

$this->storage->save($bucket);
if (0 < $tokens) {
$this->storage->save($bucket);
}
} finally {
$this->lock->release();
}
Expand Down
0