Skip to content
This repository was archived by the owner on Feb 1, 2023. It is now read-only.

Commit 4f949c5

Browse files
committed
Handle 429 too many requests coming from fuzzysearch
1 parent 6a3cc6d commit 4f949c5

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/app.php

+15
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,16 @@ function () use ($entry) {
900900

901901
$results = $this->reverseSearchFuzzySearch($this->PATH_IMAGES . '/' . $entry);
902902

903+
if (isset($results['error']) && $results['error'] === 'ShortLimitReached') {
904+
$results = $this->applyCooldown(
905+
60,
906+
$results,
907+
function () use ($entry) {
908+
return $this->reverseSearchFuzzySearch($this->PATH_IMAGES . '/' . $entry);
909+
}
910+
);
911+
}
912+
903913
if ($this->FORCE_MULTI_SEARCH) {
904914
if (isset($results_prev) && isset($service_prev) && $results_prev !== null) {
905915
/** @noinspection SlowArrayOperationsInLoopInspection */
@@ -1580,6 +1590,11 @@ private function reverseSearchFuzzySearch($file)
15801590

15811591
$result = json_decode($output, true);
15821592

1593+
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
1594+
if ($http_code === 429 || (isset($result['code']) && $result['code'] === 429)) {
1595+
return ['error' => 'ShortLimitReached'];
1596+
}
1597+
15831598
$matches = [];
15841599
if (isset($result['matches']) && count($result['matches']) > 0) {
15851600
foreach ($result['matches'] as $this_result) {

0 commit comments

Comments
 (0)