diff --git a/src/library/coverartcache.cpp b/src/library/coverartcache.cpp index e2411c2fe90b..328f3491afbd 100644 --- a/src/library/coverartcache.cpp +++ b/src/library/coverartcache.cpp @@ -157,12 +157,11 @@ void CoverArtCache::tryLoadCover( return; } - const auto requestedCacheKey = coverInfo.cacheKey(); - QString cacheKey = pixmapCacheKey(requestedCacheKey, desiredWidth); + const mixxx::cache_key_t requestedCacheKey = coverInfo.cacheKey(); // keep a list of cacheKeys for which a future is currently running // to avoid loading the same picture again while we are loading it - bool requestPending = m_runningRequests.contains(cacheKey); - m_runningRequests.insert(cacheKey, pRequester); + bool requestPending = m_runningRequests.contains(requestedCacheKey); + m_runningRequests.insert(requestedCacheKey, {pRequester, desiredWidth}); if (requestPending) { return; } @@ -294,11 +293,21 @@ void CoverArtCache::coverLoaded() { } } - const QObject* pRequester; - while ((pRequester = m_runningRequests.take(cacheKey)) != nullptr) { - emit coverFound( - pRequester, + QMultiHash::iterator i = m_runningRequests.find(res.coverArt.cacheKey()); + while (i != hash.end() && i.key() == res.coverArt.cacheKey()) { + if (i.value().desiredWidth == res.coverArt.resizedToWidth) { + emit coverFound( + i.value().pRequester, + res.coverArt, + pixmap); + } else { + tryLoadCover( + i.value().pRequester, + nullptr, res.coverArt, - pixmap); + res.coverArt.resizedToWidth); + } + hash.erase(i); + ++i; } } diff --git a/src/library/coverartcache.h b/src/library/coverartcache.h index 4fe0f1f5bf66..3b5e1d22954a 100644 --- a/src/library/coverartcache.h +++ b/src/library/coverartcache.h @@ -92,5 +92,12 @@ class CoverArtCache : public QObject, public Singleton { const CoverInfo& info, int desiredWidth); - QMultiHash m_runningRequests; + struct RequestData { + const QObject* pRequester; + int desiredWidth; + } + bool operator==(const RequestData& l, const RequestData& r) { + return l.pRequester == r.pRequester && l.desiredWidth == r.desiredWidth; + } + QMultiHash m_runningRequests; };