mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-02-16 15:19:55 +03:00
fix(reddit): tweak internal cache logic (#3831)
This commit is contained in:
parent
d157816e07
commit
0c4b498d4f
1 changed files with 12 additions and 6 deletions
|
@ -75,20 +75,26 @@ class RedditBridge extends BridgeAbstract
|
|||
|
||||
public function collectData()
|
||||
{
|
||||
$cacheKey = 'reddit_rate_limit';
|
||||
if ($this->cache->get($cacheKey)) {
|
||||
$forbiddenKey = 'reddit_forbidden';
|
||||
if ($this->cache->get($forbiddenKey)) {
|
||||
throw new HttpException('403 Forbidden', 403);
|
||||
}
|
||||
|
||||
$rateLimitKey = 'reddit_rate_limit';
|
||||
if ($this->cache->get($rateLimitKey)) {
|
||||
throw new HttpException('429 Too Many Requests', 429);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->collectDataInternal();
|
||||
} catch (HttpException $e) {
|
||||
if ($e->getCode() === 429) {
|
||||
$this->cache->set($cacheKey, true, 60 * 16);
|
||||
}
|
||||
if ($e->getCode() === 403) {
|
||||
// 403 Forbidden
|
||||
// This can possibly mean that reddit has permanently blocked this server's ip address
|
||||
$this->cache->set($cacheKey, true, 60 * 61);
|
||||
$this->cache->set($forbiddenKey, true, 60 * 61);
|
||||
}
|
||||
if ($e->getCode() === 429) {
|
||||
$this->cache->set($rateLimitKey, true, 60 * 16);
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue