mirror of
https://github.com/codeigniter4/CodeIgniter4.git
synced 2025-02-20 11:44:28 +08:00
Merge pull request #2873 from jlamim/throttler_bug
Bug fix in Throttler class check validation
This commit is contained in:
commit
246ab82658
@ -139,8 +139,7 @@ class Throttler implements ThrottlerInterface
|
||||
$tokenName = $this->prefix . $key;
|
||||
|
||||
// Check to see if the bucket has even been created yet.
|
||||
if (($tokens = $this->cache->get($tokenName)) === null)
|
||||
{
|
||||
if (($tokens = $this->cache->get($tokenName)) === null) {
|
||||
// If it hasn't been created, then we'll set it to the maximum
|
||||
// capacity - 1, and save it to the cache.
|
||||
$this->cache->save($tokenName, $capacity - $cost, $seconds);
|
||||
@ -169,10 +168,9 @@ class Throttler implements ThrottlerInterface
|
||||
$tokens += $rate * $elapsed;
|
||||
$tokens = $tokens > $capacity ? $capacity : $tokens;
|
||||
|
||||
// If $tokens > 0, then we are safe to perform the action, but
|
||||
// If $tokens >= 1, then we are safe to perform the action, but
|
||||
// we need to decrement the number of available tokens.
|
||||
if ($tokens > 0)
|
||||
{
|
||||
if ($tokens >= 1) {
|
||||
$this->cache->save($tokenName, $tokens - $cost, $seconds);
|
||||
$this->cache->save($tokenName . 'Time', time(), $seconds);
|
||||
|
||||
@ -209,5 +207,4 @@ class Throttler implements ThrottlerInterface
|
||||
{
|
||||
return $this->testTime ?? time();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user