1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-08-11 16:44:05 +02:00

Don't let cache requests go through until the cache is fully loaded

This commit is contained in:
Jeff Mitchell
2011-04-16 03:40:15 -04:00
parent 5334dbf037
commit f7c440ed4f
2 changed files with 13 additions and 0 deletions

View File

@@ -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--;
}

View File

@@ -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