Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(reddit): reduce ratelimit triggering #4168

Merged
merged 1 commit into from
Jul 28, 2024
Merged
Changes from all commits
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
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
Loading