Handles asynchronous loading of card images, both locally and via network.
More...
#include <card_picture_loader_worker.h>
|
| static constexpr int | CacheTTLInDays = 30 |
| | Time-to-live for redirect cache entries (days)
|
Handles asynchronous loading of card images, both locally and via network.
Responsibilities:
- Maintain a queue of network image requests with rate-limiting.
- Load images from local cache first via CardPictureLoaderLocal.
- Handle network redirects and persistent caching of redirects.
- Deduplicate simultaneous requests for the same card.
- Emit signals for status updates and loaded images.
◆ CardPictureLoaderWorker()
| CardPictureLoaderWorker::CardPictureLoaderWorker |
( |
| ) |
|
|
explicit |
Constructs a CardPictureLoaderWorker.
Initializes network manager, cache, redirect cache, local loader, and request quota timer.
◆ ~CardPictureLoaderWorker()
| CardPictureLoaderWorker::~CardPictureLoaderWorker |
( |
| ) |
|
|
override |
◆ cacheRedirect
| void CardPictureLoaderWorker::cacheRedirect |
( |
const QUrl & | originalUrl, |
|
|
const QUrl & | redirectUrl ) |
|
slot |
Caches a redirect mapping between original and redirected URL.
◆ cleanStaleEntries()
| void CardPictureLoaderWorker::cleanStaleEntries |
( |
| ) |
|
|
private |
Removes stale redirect entries older than TTL.
◆ clearNetworkCache()
| void CardPictureLoaderWorker::clearNetworkCache |
( |
| ) |
|
Clears the network cache and redirect cache.
◆ enqueueImageLoad()
| void CardPictureLoaderWorker::enqueueImageLoad |
( |
const ExactCard & | card | ) |
|
Enqueues an ExactCard for loading.
- Parameters
-
This will first try to load the image locally; if that fails, it will enqueue a network request.
◆ getCachedRedirect()
| QUrl CardPictureLoaderWorker::getCachedRedirect |
( |
const QUrl & | originalUrl | ) |
const |
|
nodiscardprivate |
Returns cached redirect URL for the given original URL, if available.
◆ handleImageLoaded
| void CardPictureLoaderWorker::handleImageLoaded |
( |
const ExactCard & | card, |
|
|
const QImage & | image ) |
|
slot |
Handles an image that has finished loading.
- Parameters
-
| card | The ExactCard that was loaded |
| image | The loaded QImage; empty if loading failed |
Called when image loading is done. Failures are indicated by an empty QImage.
◆ handleImageLoadEnqueued
| void CardPictureLoaderWorker::handleImageLoadEnqueued |
( |
const ExactCard & | card | ) |
|
|
privateslot |
Handles image load requests enqueued on this worker.
◆ imageLoaded
| void CardPictureLoaderWorker::imageLoaded |
( |
const ExactCard & | card, |
|
|
const QImage & | image ) |
|
signal |
Emitted when an image has finished loading.
◆ imageLoadEnqueued
| void CardPictureLoaderWorker::imageLoadEnqueued |
( |
const ExactCard & | card | ) |
|
|
signal |
Emitted when an image load is enqueued.
◆ imageRequestQueued
| void CardPictureLoaderWorker::imageRequestQueued |
( |
const QUrl & | url, |
|
|
const ExactCard & | card, |
|
|
const QString & | setName ) |
|
signal |
Emitted when a request is added to the network queue.
◆ imageRequestSucceeded
| void CardPictureLoaderWorker::imageRequestSucceeded |
( |
const QUrl & | url | ) |
|
|
signal |
Emitted when a network request successfully completes.
◆ loadRedirectCache()
| void CardPictureLoaderWorker::loadRedirectCache |
( |
| ) |
|
|
private |
Loads redirect cache from disk.
◆ makeRequest
Makes a network request for the given URL using the specified worker.
- Parameters
-
| url | URL to load |
| workThread | Worker handling the request |
- Returns
- The QNetworkReply object representing the request
◆ processQueuedRequests
| void CardPictureLoaderWorker::processQueuedRequests |
( |
| ) |
|
|
slot |
Processes all queued requests respecting the request quota.
◆ processSingleRequest
| bool CardPictureLoaderWorker::processSingleRequest |
( |
| ) |
|
|
slot |
Processes a single queued request.
- Returns
- true if a request was processed, false if queue is empty.
◆ queueRequest()
Queues a network request for a given URL and worker thread.
- Parameters
-
| url | URL to load |
| worker | Worker handling this request |
◆ removedCachedUrl
| void CardPictureLoaderWorker::removedCachedUrl |
( |
const QUrl & | url | ) |
|
|
slot |
Removes a URL from the network cache.
◆ resetRequestQuota
| void CardPictureLoaderWorker::resetRequestQuota |
( |
| ) |
|
|
privateslot |
Resets the request quota for rate-limiting.
◆ saveRedirectCache()
| void CardPictureLoaderWorker::saveRedirectCache |
( |
| ) |
const |
|
private |
Saves redirect cache to disk.
◆ cache
| QNetworkDiskCache* CardPictureLoaderWorker::cache |
|
private |
Disk cache for downloaded images.
◆ cacheFilePath
| QString CardPictureLoaderWorker::cacheFilePath |
|
private |
Path to persistent redirect cache file.
◆ CacheTTLInDays
| int CardPictureLoaderWorker::CacheTTLInDays = 30 |
|
staticconstexprprivate |
Time-to-live for redirect cache entries (days)
◆ currentlyLoading
| QSet<QString> CardPictureLoaderWorker::currentlyLoading |
|
private |
Deduplication: contains pixmapCacheKey currently being loaded.
◆ localLoader
◆ networkManager
| QNetworkAccessManager* CardPictureLoaderWorker::networkManager |
|
private |
Network manager for HTTP requests.
◆ picDownload
| bool CardPictureLoaderWorker::picDownload |
|
private |
Whether downloading images from network is enabled.
◆ pictureLoaderThread
| QThread* CardPictureLoaderWorker::pictureLoaderThread |
|
private |
Thread for executing worker tasks.
◆ redirectCache
| QHash<QUrl, QPair<QUrl, QDateTime> > CardPictureLoaderWorker::redirectCache |
|
private |
Maps original URLs to redirects with timestamp.
◆ requestLoadQueue
Queue of pending network requests.
◆ requestQuota
| int CardPictureLoaderWorker::requestQuota |
|
private |
Remaining requests allowed per second.
◆ requestTimer
| QTimer CardPictureLoaderWorker::requestTimer |
|
private |
Timer to reset the request quota.
The documentation for this class was generated from the following files: