Skip to content

Commit

Permalink
fix: ensure ratelimit expiry is set every time
Browse files Browse the repository at this point in the history
  • Loading branch information
bshaffer committed Jan 17, 2024
1 parent 1b9e871 commit 9cf1cbc
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/CachedKeySet.php
Expand Up @@ -212,15 +212,24 @@ private function rateLimitExceeded(): bool
}

$cacheItem = $this->cache->getItem($this->rateLimitCacheKey);
<<<<<<< Updated upstream

Check failure on line 215 in src/CachedKeySet.php

View workflow job for this annotation

GitHub Actions / PHPStan Static Analysis

Syntax error, unexpected T_SL on line 215
if (!$cacheItem->isHit()) {
$cacheItem->expiresAfter(60); // # of calls are cached each minute
=======

Check failure on line 218 in src/CachedKeySet.php

View workflow job for this annotation

GitHub Actions / PHPStan Static Analysis

Syntax error, unexpected T_IS_IDENTICAL on line 218
if (!$cacheItem->isHit() || !is_array($cacheItemData = $cacheItem->get())) {
$cacheItemData = [
'callsPerMinute' => 0,
'expiry' => new \DateTime('+60 seconds', new \DateTimeZone('UTC')),
];
>>>>>>> Stashed changes

Check failure on line 224 in src/CachedKeySet.php

View workflow job for this annotation

GitHub Actions / PHPStan Static Analysis

Syntax error, unexpected T_SR on line 224
}

$callsPerMinute = (int) $cacheItem->get();
if (++$callsPerMinute > $this->maxCallsPerMinute) {
if (++$cacheItemData['callsPerMinute'] > $this->maxCallsPerMinute) {
return true;
}
$cacheItem->set($callsPerMinute);

$cacheItem->set($cacheItemData);
$cacheItem->expiresAt($cacheItemData['expiry']);
$this->cache->save($cacheItem);
return false;
}
Expand Down

0 comments on commit 9cf1cbc

Please sign in to comment.