Skip to content

Commit

Permalink
fix(reddit): increase default cache ttl (#4168)
Browse files Browse the repository at this point in the history
  • Loading branch information
dvikan authored Jul 28, 2024
1 parent 8dd56bc commit 955fb6f
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions bridges/RedditBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class RedditBridge extends BridgeAbstract
const MAINTAINER = 'dawidsowa';
const NAME = 'Reddit Bridge';
const URI = 'https://old.reddit.com';
const CACHE_TIMEOUT = 60 * 60 * 2; // 2h
const DESCRIPTION = 'Return hot submissions from Reddit';

const PARAMETERS = [
Expand Down Expand Up @@ -107,9 +108,8 @@ public function collectData()
// 403 Forbidden
// This can possibly mean that reddit has permanently blocked this server's ip address
$this->cache->set($forbiddenKey, true, 60 * 61);
}
if ($e->getCode() === 429) {
$this->cache->set($rateLimitKey, true, 60 * 16);
} elseif ($e->getCode() === 429) {
$this->cache->set($rateLimitKey, true, 60 * 61);
}
throw $e;
}
Expand Down Expand Up @@ -143,10 +143,14 @@ private function collectDataInternal(): void
$flareInput = $this->getInput('f');

foreach ($subreddits as $subreddit) {
$version = 'v0.0.1';
$version = 'v0.0.2';
$useragent = "rss-bridge $version (https://github.com/RSS-Bridge/rss-bridge)";
$url = self::createUrl($search, $flareInput, $subreddit, $user, $section, $this->queriedContext);
$json = getContents($url, ['User-Agent: ' . $useragent]);

$response = getContents($url, ['User-Agent: ' . $useragent], [], true);

$json = $response['content'];

$parsedJson = Json::decode($json, false);

foreach ($parsedJson->data->children as $post) {
Expand Down

0 comments on commit 955fb6f

Please sign in to comment.