mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -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();
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(responseData);
|
||||
|
||||
if (jsonDoc.isObject()) {
|
||||
QJsonObject jsonObj = jsonDoc.object();
|
||||
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
|
||||
rateLimited = true;
|
||||
qWarning() << "Scryfall rate limit hit!";
|
||||
// Prevent multiple rate-limit handling
|
||||
if (!rateLimited) {
|
||||
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));
|
||||
|
||||
// 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")
|
||||
<< ", no more url combinations to try: BAILING OUT";
|
||||
imageLoaded(cardToDownload.getCard(), QImage());
|
||||
cardToDownload.clear();
|
||||
}
|
||||
emit startLoadQueue();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue