Fix double free requests from cache hit

If we hit a cached url, the request already gets to skip the queue.
By sending another free request once the cached request finishes, we're actually sending two free requests on each cache hit.
This commit is contained in:
RickyRister 2025-07-03 23:26:04 -07:00
parent 1db47fa116
commit d178e4a2a7
3 changed files with 1 additions and 10 deletions

View file

@ -12,7 +12,6 @@
#include <QThread> #include <QThread>
#include <utility> #include <utility>
PictureLoaderWorker::PictureLoaderWorker() : QObject(nullptr), picDownload(SettingsCache::instance().getPicDownload()) PictureLoaderWorker::PictureLoaderWorker() : QObject(nullptr), picDownload(SettingsCache::instance().getPicDownload())
{ {
networkManager = new QNetworkAccessManager(this); networkManager = new QNetworkAccessManager(this);
@ -66,6 +65,7 @@ void PictureLoaderWorker::queueRequest(const QUrl &url, PictureLoaderWorkerWork
if (!cachedRedirect.isEmpty()) { if (!cachedRedirect.isEmpty()) {
queueRequest(cachedRedirect, worker); queueRequest(cachedRedirect, worker);
} else if (cache->metaData(url).isValid()) { } else if (cache->metaData(url).isValid()) {
// If we hit a cached url, we get to make the request for free, since it won't contribute towards the rate-limit
makeRequest(url, worker); makeRequest(url, worker);
} else { } else {
requestLoadQueue.append(qMakePair(url, worker)); requestLoadQueue.append(qMakePair(url, worker));

View file

@ -20,7 +20,6 @@ PictureLoaderWorkerWork::PictureLoaderWorkerWork(const PictureLoaderWorker *work
{ {
// Hook up signals to the orchestrator // Hook up signals to the orchestrator
connect(this, &PictureLoaderWorkerWork::requestImageDownload, worker, &PictureLoaderWorker::queueRequest); connect(this, &PictureLoaderWorkerWork::requestImageDownload, worker, &PictureLoaderWorker::queueRequest);
connect(this, &PictureLoaderWorkerWork::cachedImageHit, worker, &PictureLoaderWorker::processSingleRequest);
connect(this, &PictureLoaderWorkerWork::urlRedirected, worker, &PictureLoaderWorker::cacheRedirect); connect(this, &PictureLoaderWorkerWork::urlRedirected, worker, &PictureLoaderWorker::cacheRedirect);
connect(this, &PictureLoaderWorkerWork::cachedUrlInvalidated, worker, &PictureLoaderWorker::removedCachedUrl); connect(this, &PictureLoaderWorkerWork::cachedUrlInvalidated, worker, &PictureLoaderWorker::removedCachedUrl);
connect(this, &PictureLoaderWorkerWork::imageLoaded, worker, &PictureLoaderWorker::imageLoadedSuccessfully); connect(this, &PictureLoaderWorkerWork::imageLoaded, worker, &PictureLoaderWorker::imageLoadedSuccessfully);
@ -97,10 +96,6 @@ void PictureLoaderWorkerWork::handleNetworkReply(QNetworkReply *reply)
if (reply->error()) { if (reply->error()) {
handleFailedReply(reply); handleFailedReply(reply);
} else { } else {
if (reply->attribute(QNetworkRequest::SourceIsFromCacheAttribute).toBool()) {
emit cachedImageHit();
}
handleSuccessfulReply(reply); handleSuccessfulReply(reply);
} }

View file

@ -55,10 +55,6 @@ signals:
void imageLoaded(CardInfoPtr card, const QImage &image); void imageLoaded(CardInfoPtr card, const QImage &image);
void requestImageDownload(const QUrl &url, PictureLoaderWorkerWork *instance); void requestImageDownload(const QUrl &url, PictureLoaderWorkerWork *instance);
/**
* We hit a cached image from the network cache; we get to make another request for free.
*/
void cachedImageHit();
void urlRedirected(const QUrl &originalUrl, const QUrl &redirectUrl); void urlRedirected(const QUrl &originalUrl, const QUrl &redirectUrl);
void cachedUrlInvalidated(const QUrl &url); void cachedUrlInvalidated(const QUrl &url);
}; };