Format picture-loader changes using project style

This commit is contained in:
Bryce! 2026-11-02 00:34:34 -05:00
parent 5d7ddf69b8
commit c28acf8ba6
4 changed files with 26 additions and 30 deletions

View file

@ -4,9 +4,9 @@
#include <QBuffer> #include <QBuffer>
#include <QByteArray> #include <QByteArray>
#include <QByteArrayList> #include <QByteArrayList>
#include <QIODevice>
#include <QImage> #include <QImage>
#include <QImageReader> #include <QImageReader>
#include <QIODevice>
#include <QMovie> #include <QMovie>
#include <QString> #include <QString>

View file

@ -6,9 +6,9 @@
#include "card_picture_loader_local.h" #include "card_picture_loader_local.h"
#include "card_picture_loader_worker_work.h" #include "card_picture_loader_worker_work.h"
#include "card_picture_to_load.h" #include "card_picture_to_load.h"
#include "redirect_chain.h"
#include "libcockatrice/card/printing/exact_card.h" #include "libcockatrice/card/printing/exact_card.h"
#include "libcockatrice/utility/server_rate_limiter.h" #include "libcockatrice/utility/server_rate_limiter.h"
#include "redirect_chain.h"
#include <QAbstractNetworkCache> #include <QAbstractNetworkCache>
#include <QByteArray> #include <QByteArray>
@ -102,23 +102,22 @@ CardPictureLoaderWorker::CardPictureLoaderWorker()
connect(&SettingsCache::instance().downloads(), &DownloadSettings::hostRequestLimitsChanged, this, connect(&SettingsCache::instance().downloads(), &DownloadSettings::hostRequestLimitsChanged, this,
[this] { hostRequestLimits = SettingsCache::instance().downloads().getHostRequestLimits(); }); [this] { hostRequestLimits = SettingsCache::instance().downloads().getHostRequestLimits(); });
connect(&SettingsCache::instance().downloads(), &DownloadSettings::picDownloadChanged, this, connect(&SettingsCache::instance().downloads(), &DownloadSettings::picDownloadChanged, this, [this] {
[this] { picDownload = SettingsCache::instance().downloads().getPicDownload();
picDownload = SettingsCache::instance().downloads().getPicDownload(); if (!picDownload) {
if (!picDownload) { // Waiting for network quota or 429 recovery cannot help a cache-only lookup.
// Waiting for network quota or 429 recovery cannot help a cache-only lookup. // Retire cancelled status entries just as the normal dispatcher does.
// Retire cancelled status entries just as the normal dispatcher does. while (!requestLoadQueue.isEmpty()) {
while (!requestLoadQueue.isEmpty()) { const auto entry = requestLoadQueue.takeFirst();
const auto entry = requestLoadQueue.takeFirst(); if (entry.second) {
if (entry.second) { makeRequest(entry.first, entry.second);
makeRequest(entry.first, entry.second); } else {
} else { emit imageRequestSucceeded(entry.first);
emit imageRequestSucceeded(entry.first);
}
}
updateTimerState();
} }
}); }
updateTimerState();
}
});
} }
CardPictureLoaderWorker::~CardPictureLoaderWorker() CardPictureLoaderWorker::~CardPictureLoaderWorker()
@ -157,9 +156,9 @@ void CardPictureLoaderWorker::queueRequest(const QUrl &url, CardPictureLoaderWor
{ {
const QUrl resolvedUrl = resolveCachedRedirect(url); const QUrl resolvedUrl = resolveCachedRedirect(url);
if (!picDownload || (static_cast<CardPictureLoaderCacheMethod::CacheMethod>( if (!picDownload || (static_cast<CardPictureLoaderCacheMethod::CacheMethod>(
SettingsCache::instance().cacheStorage().getCardPictureLoaderCacheMethod()) == SettingsCache::instance().cacheStorage().getCardPictureLoaderCacheMethod()) ==
CardPictureLoaderCacheMethod::CacheMethod::NETWORK_CACHE && CardPictureLoaderCacheMethod::CacheMethod::NETWORK_CACHE &&
cache->metaData(resolvedUrl).isValid() && !worker->shouldBypassCache(resolvedUrl))) { cache->metaData(resolvedUrl).isValid() && !worker->shouldBypassCache(resolvedUrl))) {
// A request that will be served from the disk cache never touches the network and therefore // A request that will be served from the disk cache never touches the network and therefore
// doesn't use up any of the rate limit, so it gets to skip the queue. // doesn't use up any of the rate limit, so it gets to skip the queue.
// Every reply retires a status, including online cache hits and deferred // Every reply retires a status, including online cache hits and deferred
@ -180,9 +179,8 @@ QNetworkReply *CardPictureLoaderWorker::makeRequest(const QUrl &url, CardPicture
const QUrl resolvedUrl = resolveCachedRedirect(url); const QUrl resolvedUrl = resolveCachedRedirect(url);
if (resolvedUrl != url) { if (resolvedUrl != url) {
emit imageRequestSucceeded(url); emit imageRequestSucceeded(url);
if (requestTouchesNetwork(resolvedUrl, worker) && if (requestTouchesNetwork(resolvedUrl, worker) && CardPictureLoaderWorkerWork::rateLimiter().isRateLimited(
CardPictureLoaderWorkerWork::rateLimiter().isRateLimited(resolvedUrl.host(), resolvedUrl.host(), QDateTime::currentDateTime())) {
QDateTime::currentDateTime())) {
worker->scheduleDeferredRetry(resolvedUrl.host()); worker->scheduleDeferredRetry(resolvedUrl.host());
return nullptr; return nullptr;
} }
@ -443,8 +441,7 @@ bool CardPictureLoaderWorker::processSingleRequest()
return false; return false;
} }
bool CardPictureLoaderWorker::requestTouchesNetwork(const QUrl &url, bool CardPictureLoaderWorker::requestTouchesNetwork(const QUrl &url, const CardPictureLoaderWorkerWork *worker) const
const CardPictureLoaderWorkerWork *worker) const
{ {
if (!picDownload) { if (!picDownload) {
return false; return false;

View file

@ -263,8 +263,7 @@ void CardPictureLoaderWorkerWork::handleSuccessfulReply(QNetworkReply *reply)
int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt(); int statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
if (statusCode == 301 || statusCode == 302 || statusCode == 303 || statusCode == 305 || statusCode == 307 || if (statusCode == 301 || statusCode == 302 || statusCode == 303 || statusCode == 305 || statusCode == 307 ||
statusCode == 308) { statusCode == 308) {
QUrl redirectUrl = reply->url().resolved( QUrl redirectUrl = reply->url().resolved(reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl());
reply->attribute(QNetworkRequest::RedirectionTargetAttribute).toUrl());
qCDebug(CardPictureLoaderWorkerWorkLog).nospace() qCDebug(CardPictureLoaderWorkerWorkLog).nospace()
<< "PictureLoader: [card: " << cardToDownload.getCard().getName() << " set: " << cardToDownload.getSetName() << "PictureLoader: [card: " << cardToDownload.getCard().getName() << " set: " << cardToDownload.getSetName()
<< "]: following " << (isFromCache ? "cached redirect" : "redirect") << " to " << "]: following " << (isFromCache ? "cached redirect" : "redirect") << " to "

View file

@ -6,8 +6,8 @@
#include <QImage> #include <QImage>
#include <QLoggingCategory> #include <QLoggingCategory>
#include <QObject> #include <QObject>
#include <QString>
#include <QSet> #include <QSet>
#include <QString>
#include <QTimer> #include <QTimer>
#include <QUrl> #include <QUrl>
#include <qtmetamacros.h> #include <qtmetamacros.h>
@ -80,7 +80,7 @@ public slots:
void handleNetworkReply(QNetworkReply *reply); void handleNetworkReply(QNetworkReply *reply);
private: private:
bool picDownload; ///< Whether network downloading is enabled bool picDownload; ///< Whether network downloading is enabled
QTimer *deferredRetry = nullptr; ///< Owned retry, cancellable when downloads are disabled QTimer *deferredRetry = nullptr; ///< Owned retry, cancellable when downloads are disabled
QSet<QUrl> retriedCacheUrls; QSet<QUrl> retriedCacheUrls;