1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-03-24 01:39:42 +01:00

Fix some objects in cache being "lost", such as similar artists/top

artist songs
This commit is contained in:
Jeff Mitchell 2011-07-12 16:38:16 -04:00
parent e83be2b9cd
commit 43a1b38a49
3 changed files with 14 additions and 10 deletions

View File

@ -129,6 +129,7 @@ InfoSystemCache::getCachedInfoSlot( uint requestId, Tomahawk::InfoSystem::InfoCr
{
qDebug() << Q_FUNC_INFO;
const QString criteriaHashVal = criteriaMd5( criteria );
const QString criteriaHashValWithType = criteriaMd5( criteria, requestData.type );
QHash< QString, QString > fileLocationHash = m_fileLocationCache[ requestData.type ];
if ( !fileLocationHash.contains( criteriaHashVal ) )
{
@ -180,7 +181,7 @@ InfoSystemCache::getCachedInfoSlot( uint requestId, Tomahawk::InfoSystem::InfoCr
fileLocationHash.remove( criteriaHashVal );
m_fileLocationCache[ requestData.type ] = fileLocationHash;
m_dataCache.remove( criteriaHashVal );
m_dataCache.remove( criteriaHashValWithType );
qDebug() << Q_FUNC_INFO << " notInCache -- file was stale";
emit notInCache( requestId, criteria, requestData );
@ -201,17 +202,17 @@ InfoSystemCache::getCachedInfoSlot( uint requestId, Tomahawk::InfoSystem::InfoCr
m_fileLocationCache[ requestData.type ] = fileLocationHash;
}
if ( !m_dataCache.contains( criteriaHashVal ) )
if ( !m_dataCache.contains( criteriaHashValWithType ) )
{
QSettings cachedSettings( fileLocationHash[ criteriaHashVal ], QSettings::IniFormat );
QVariant output = cachedSettings.value( "data" );
m_dataCache.insert( criteriaHashVal, new QVariant( output ) );
m_dataCache.insert( criteriaHashValWithType, new QVariant( output ) );
emit info( requestId, requestData, output );
}
else
{
emit info( requestId, requestData, QVariant( *( m_dataCache[ criteriaHashVal ] ) ) );
emit info( requestId, requestData, QVariant( *( m_dataCache[ criteriaHashValWithType ] ) ) );
}
}
@ -222,6 +223,7 @@ InfoSystemCache::updateCacheSlot( Tomahawk::InfoSystem::InfoCriteriaHash criteri
qDebug() << Q_FUNC_INFO;
const QString criteriaHashVal = criteriaMd5( criteria );
const QString criteriaHashValWithType = criteriaMd5( criteria, type );
const QString cacheDir = m_cacheBaseDir + QString::number( (int)type );
const QString settingsFilePath( cacheDir + '/' + criteriaHashVal + '.' + QString::number( QDateTime::currentMSecsSinceEpoch() + maxAge ) );
@ -239,7 +241,7 @@ InfoSystemCache::updateCacheSlot( Tomahawk::InfoSystem::InfoCriteriaHash criteri
QSettings cachedSettings( fileLocationHash[ criteriaHashVal ], QSettings::IniFormat );
cachedSettings.setValue( "data", output );
m_dataCache.insert( criteriaHashVal, new QVariant( output ) );
m_dataCache.insert( criteriaHashValWithType, new QVariant( output ) );
return;
}
@ -265,18 +267,20 @@ InfoSystemCache::updateCacheSlot( Tomahawk::InfoSystem::InfoCriteriaHash criteri
fileLocationHash[criteriaHashVal] = settingsFilePath;
m_fileLocationCache[type] = fileLocationHash;
m_dataCache.insert( criteriaHashVal, new QVariant( output ) );
m_dataCache.insert( criteriaHashValWithType, new QVariant( output ) );
}
const QString
InfoSystemCache::criteriaMd5( const Tomahawk::InfoSystem::InfoCriteriaHash &criteria ) const
InfoSystemCache::criteriaMd5( const Tomahawk::InfoSystem::InfoCriteriaHash &criteria, Tomahawk::InfoSystem::InfoType type ) const
{
QCryptographicHash hash( QCryptographicHash::Md5 );
foreach( QString key, criteria.keys() )
hash.addData( key.toUtf8() );
foreach( QString value, criteria.values() )
hash.addData( value.toUtf8() );
if ( type != Tomahawk::InfoSystem::InfoNoInfo )
hash.addData( QString::number( (int)type ).toUtf8() );
return hash.result().toHex();
}

View File

@ -55,7 +55,7 @@ private slots:
private:
void doUpgrade( uint oldVersion, uint newVersion );
const QString criteriaMd5( const Tomahawk::InfoSystem::InfoCriteriaHash &criteria ) const;
const QString criteriaMd5( const Tomahawk::InfoSystem::InfoCriteriaHash &criteria, Tomahawk::InfoSystem::InfoType type = Tomahawk::InfoSystem::InfoNoInfo ) const;
QString m_cacheBaseDir;
QHash< InfoType, QHash< QString, QString > > m_fileLocationCache;

View File

@ -188,7 +188,7 @@ InfoSystemWorker::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData, ui
}
qDebug() << "assigning request with requestId " << requestId << " and type " << requestData.type;
m_dataTracker[ requestData.caller ][ requestData.type ] = m_dataTracker[ requestData.caller ][ requestData.type ] + 1;
qDebug() << "current count in dataTracker for type" << requestData.type << "is" << m_dataTracker[ requestData.caller ][ requestData.type ];
qDebug() << "current count in dataTracker for target " << requestData.caller << " and type" << requestData.type << "is" << m_dataTracker[ requestData.caller ][ requestData.type ];
InfoRequestData* data = new InfoRequestData;
data->caller = requestData.caller;
@ -233,7 +233,7 @@ InfoSystemWorker::infoSlot( uint requestId, Tomahawk::InfoSystem::InfoRequestDat
emit info( requestData, output );
m_dataTracker[ requestData.caller ][ requestData.type ] = m_dataTracker[ requestData.caller ][ requestData.type ] - 1;
qDebug() << "current count in dataTracker for target " << requestData.caller << " is " << m_dataTracker[ requestData.caller ][ requestData.type ];
qDebug() << "current count in dataTracker for target " << requestData.caller << " and type " << requestData.type << " is " << m_dataTracker[ requestData.caller ][ requestData.type ];
delete m_savedRequestMap[ requestId ];
m_savedRequestMap.remove( requestId );
checkFinished( requestData.caller );