diff --git a/cockatrice/src/client/ui/picture_loader/picture_loader_worker.cpp b/cockatrice/src/client/ui/picture_loader/picture_loader_worker.cpp index 0cc8c86e1..63dd1b8a4 100644 --- a/cockatrice/src/client/ui/picture_loader/picture_loader_worker.cpp +++ b/cockatrice/src/client/ui/picture_loader/picture_loader_worker.cpp @@ -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); } } } diff --git a/cockatrice/src/client/ui/picture_loader/picture_loader_worker_work.cpp b/cockatrice/src/client/ui/picture_loader/picture_loader_worker_work.cpp index 31707d2bb..90dd311be 100644 --- a/cockatrice/src/client/ui/picture_loader/picture_loader_worker_work.cpp +++ b/cockatrice/src/client/ui/picture_loader/picture_loader_worker_work.cpp @@ -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(); }