From f7c440ed4f206508f84059e3e5ce44ec24e22eda Mon Sep 17 00:00:00 2001 From: Jeff Mitchell Date: Sat, 16 Apr 2011 03:40:15 -0400 Subject: [PATCH] Don't let cache requests go through until the cache is fully loaded --- src/libtomahawk/infosystem/infosystemcache.cpp | 12 ++++++++++++ src/libtomahawk/infosystem/infosystemcache.h | 1 + 2 files changed, 13 insertions(+) diff --git a/src/libtomahawk/infosystem/infosystemcache.cpp b/src/libtomahawk/infosystem/infosystemcache.cpp index 17d0ac906..7b89539c1 100644 --- a/src/libtomahawk/infosystem/infosystemcache.cpp +++ b/src/libtomahawk/infosystem/infosystemcache.cpp @@ -33,6 +33,7 @@ namespace InfoSystem InfoSystemCache::InfoSystemCache( QObject* parent ) : QObject(parent) + , m_cacheRemainingToLoad( 0 ) { qDebug() << Q_FUNC_INFO; QString cacheBaseDir = QDesktopServices::storageLocation( QDesktopServices::CacheLocation ); @@ -43,7 +44,10 @@ InfoSystemCache::InfoSystemCache( QObject* parent ) QString cacheFile = cacheDir + '/' + QString::number( i ); QDir dir( cacheDir ); if( dir.exists() && QFile::exists( cacheFile ) ) + { + m_cacheRemainingToLoad++; QMetaObject::invokeMethod( this, "loadCache", Qt::QueuedConnection, Q_ARG( Tomahawk::InfoSystem::InfoType, type ), Q_ARG( QString, cacheFile ) ); + } } } @@ -74,6 +78,13 @@ InfoSystemCache::getCachedInfoSlot( Tomahawk::InfoSystem::InfoCacheCriteria crit emit notInCache( criteria, caller, type, input, customData ); return; } + + if ( m_cacheRemainingToLoad > 0 ) + { + qDebug() << "Cache not fully loaded, punting request for a bit"; + QMetaObject::invokeMethod( this, "getCachedInfoSlot", Qt::QueuedConnection, Q_ARG( Tomahawk::InfoSystem::InfoCacheCriteria, criteria ), Q_ARG( qint64, newMaxAge ), Q_ARG( QString, caller ), Q_ARG( Tomahawk::InfoSystem::InfoType, type ), Q_ARG( Tomahawk::InfoSystem::InfoCustomData, customData ) ); + return; + } QHash< InfoCacheCriteria, QDateTime > typemaxtimecache = m_maxTimeCache[type]; @@ -153,6 +164,7 @@ InfoSystemCache::loadCache( Tomahawk::InfoSystem::InfoType type, const QString & m_insertTimeCache[type] = insertDateHash; m_maxTimeCache[type] = maxDateHash; } + m_cacheRemainingToLoad--; } diff --git a/src/libtomahawk/infosystem/infosystemcache.h b/src/libtomahawk/infosystem/infosystemcache.h index 38e626878..bf712c8d0 100644 --- a/src/libtomahawk/infosystem/infosystemcache.h +++ b/src/libtomahawk/infosystem/infosystemcache.h @@ -57,6 +57,7 @@ private: QHash< InfoType, QHash< InfoCacheCriteria, QDateTime > > m_insertTimeCache; QHash< InfoType, QHash< InfoCacheCriteria, QDateTime > > m_maxTimeCache; QSet< InfoType > m_dirtySet; + int m_cacheRemainingToLoad; }; } //namespace InfoSystem