mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-24 15:43:54 -07:00
At least realize when we hit the rate limit and then back off for a time.
This commit is contained in:
parent
93a98eca0c
commit
6d2f6b86be
2 changed files with 15 additions and 8 deletions
|
|
@ -106,18 +106,26 @@ void PictureLoaderWorker::handleRateLimit(QNetworkReply *reply, const QUrl &url,
|
||||||
{
|
{
|
||||||
QByteArray responseData = reply->readAll();
|
QByteArray responseData = reply->readAll();
|
||||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(responseData);
|
QJsonDocument jsonDoc = QJsonDocument::fromJson(responseData);
|
||||||
|
|
||||||
if (jsonDoc.isObject()) {
|
if (jsonDoc.isObject()) {
|
||||||
QJsonObject jsonObj = jsonDoc.object();
|
QJsonObject jsonObj = jsonDoc.object();
|
||||||
if (jsonObj.value("object").toString() == "error" && jsonObj.value("code").toString() == "rate_limited") {
|
if (jsonObj.value("object").toString() == "error" && jsonObj.value("code").toString() == "rate_limited") {
|
||||||
int retryAfter = 70;
|
int retryAfter = 70; // Default retry delay
|
||||||
|
|
||||||
// Enable rate-limiting and queue the request
|
// Prevent multiple rate-limit handling
|
||||||
rateLimited = true;
|
if (!rateLimited) {
|
||||||
qWarning() << "Scryfall rate limit hit!";
|
rateLimited = true;
|
||||||
|
qWarning() << "Scryfall rate limit hit! Queuing requests for" << retryAfter << "seconds.";
|
||||||
|
|
||||||
|
// Start a timer to reset the rate-limited state
|
||||||
|
rateLimitTimer.singleShot(retryAfter * 1000, this, [this]() {
|
||||||
|
qWarning() << "Rate limit expired. Resuming queued requests.";
|
||||||
|
processQueuedRequests();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Always queue the request even if already rate-limited
|
||||||
requestQueue.append(qMakePair(url, worker));
|
requestQueue.append(qMakePair(url, worker));
|
||||||
|
|
||||||
// Start a timer to reset rate-limiting
|
|
||||||
rateLimitTimer.singleShot(retryAfter * 1000, this, &PictureLoaderWorker::processQueuedRequests);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,6 @@ void PictureLoaderWorkerWork::picDownloadFailed()
|
||||||
<< (picDownload ? "download failed" : "downloads disabled")
|
<< (picDownload ? "download failed" : "downloads disabled")
|
||||||
<< ", no more url combinations to try: BAILING OUT";
|
<< ", no more url combinations to try: BAILING OUT";
|
||||||
imageLoaded(cardToDownload.getCard(), QImage());
|
imageLoaded(cardToDownload.getCard(), QImage());
|
||||||
cardToDownload.clear();
|
|
||||||
}
|
}
|
||||||
emit startLoadQueue();
|
emit startLoadQueue();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue