mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 11:20:22 +02:00
Fix some objects in cache being "lost", such as similar artists/top
artist songs
This commit is contained in:
@@ -129,6 +129,7 @@ InfoSystemCache::getCachedInfoSlot( uint requestId, Tomahawk::InfoSystem::InfoCr
|
|||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
qDebug() << Q_FUNC_INFO;
|
||||||
const QString criteriaHashVal = criteriaMd5( criteria );
|
const QString criteriaHashVal = criteriaMd5( criteria );
|
||||||
|
const QString criteriaHashValWithType = criteriaMd5( criteria, requestData.type );
|
||||||
QHash< QString, QString > fileLocationHash = m_fileLocationCache[ requestData.type ];
|
QHash< QString, QString > fileLocationHash = m_fileLocationCache[ requestData.type ];
|
||||||
if ( !fileLocationHash.contains( criteriaHashVal ) )
|
if ( !fileLocationHash.contains( criteriaHashVal ) )
|
||||||
{
|
{
|
||||||
@@ -180,7 +181,7 @@ InfoSystemCache::getCachedInfoSlot( uint requestId, Tomahawk::InfoSystem::InfoCr
|
|||||||
|
|
||||||
fileLocationHash.remove( criteriaHashVal );
|
fileLocationHash.remove( criteriaHashVal );
|
||||||
m_fileLocationCache[ requestData.type ] = fileLocationHash;
|
m_fileLocationCache[ requestData.type ] = fileLocationHash;
|
||||||
m_dataCache.remove( criteriaHashVal );
|
m_dataCache.remove( criteriaHashValWithType );
|
||||||
|
|
||||||
qDebug() << Q_FUNC_INFO << " notInCache -- file was stale";
|
qDebug() << Q_FUNC_INFO << " notInCache -- file was stale";
|
||||||
emit notInCache( requestId, criteria, requestData );
|
emit notInCache( requestId, criteria, requestData );
|
||||||
@@ -201,17 +202,17 @@ InfoSystemCache::getCachedInfoSlot( uint requestId, Tomahawk::InfoSystem::InfoCr
|
|||||||
m_fileLocationCache[ requestData.type ] = fileLocationHash;
|
m_fileLocationCache[ requestData.type ] = fileLocationHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !m_dataCache.contains( criteriaHashVal ) )
|
if ( !m_dataCache.contains( criteriaHashValWithType ) )
|
||||||
{
|
{
|
||||||
QSettings cachedSettings( fileLocationHash[ criteriaHashVal ], QSettings::IniFormat );
|
QSettings cachedSettings( fileLocationHash[ criteriaHashVal ], QSettings::IniFormat );
|
||||||
QVariant output = cachedSettings.value( "data" );
|
QVariant output = cachedSettings.value( "data" );
|
||||||
m_dataCache.insert( criteriaHashVal, new QVariant( output ) );
|
m_dataCache.insert( criteriaHashValWithType, new QVariant( output ) );
|
||||||
|
|
||||||
emit info( requestId, requestData, output );
|
emit info( requestId, requestData, output );
|
||||||
}
|
}
|
||||||
else
|
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;
|
qDebug() << Q_FUNC_INFO;
|
||||||
|
|
||||||
const QString criteriaHashVal = criteriaMd5( criteria );
|
const QString criteriaHashVal = criteriaMd5( criteria );
|
||||||
|
const QString criteriaHashValWithType = criteriaMd5( criteria, type );
|
||||||
const QString cacheDir = m_cacheBaseDir + QString::number( (int)type );
|
const QString cacheDir = m_cacheBaseDir + QString::number( (int)type );
|
||||||
const QString settingsFilePath( cacheDir + '/' + criteriaHashVal + '.' + QString::number( QDateTime::currentMSecsSinceEpoch() + maxAge ) );
|
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 );
|
QSettings cachedSettings( fileLocationHash[ criteriaHashVal ], QSettings::IniFormat );
|
||||||
cachedSettings.setValue( "data", output );
|
cachedSettings.setValue( "data", output );
|
||||||
|
|
||||||
m_dataCache.insert( criteriaHashVal, new QVariant( output ) );
|
m_dataCache.insert( criteriaHashValWithType, new QVariant( output ) );
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -265,18 +267,20 @@ InfoSystemCache::updateCacheSlot( Tomahawk::InfoSystem::InfoCriteriaHash criteri
|
|||||||
|
|
||||||
fileLocationHash[criteriaHashVal] = settingsFilePath;
|
fileLocationHash[criteriaHashVal] = settingsFilePath;
|
||||||
m_fileLocationCache[type] = fileLocationHash;
|
m_fileLocationCache[type] = fileLocationHash;
|
||||||
m_dataCache.insert( criteriaHashVal, new QVariant( output ) );
|
m_dataCache.insert( criteriaHashValWithType, new QVariant( output ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const QString
|
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 );
|
QCryptographicHash hash( QCryptographicHash::Md5 );
|
||||||
foreach( QString key, criteria.keys() )
|
foreach( QString key, criteria.keys() )
|
||||||
hash.addData( key.toUtf8() );
|
hash.addData( key.toUtf8() );
|
||||||
foreach( QString value, criteria.values() )
|
foreach( QString value, criteria.values() )
|
||||||
hash.addData( value.toUtf8() );
|
hash.addData( value.toUtf8() );
|
||||||
|
if ( type != Tomahawk::InfoSystem::InfoNoInfo )
|
||||||
|
hash.addData( QString::number( (int)type ).toUtf8() );
|
||||||
return hash.result().toHex();
|
return hash.result().toHex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -55,7 +55,7 @@ private slots:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void doUpgrade( uint oldVersion, uint newVersion );
|
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;
|
QString m_cacheBaseDir;
|
||||||
QHash< InfoType, QHash< QString, QString > > m_fileLocationCache;
|
QHash< InfoType, QHash< QString, QString > > m_fileLocationCache;
|
||||||
|
@@ -188,7 +188,7 @@ InfoSystemWorker::getInfo( Tomahawk::InfoSystem::InfoRequestData requestData, ui
|
|||||||
}
|
}
|
||||||
qDebug() << "assigning request with requestId " << requestId << " and type " << requestData.type;
|
qDebug() << "assigning request with requestId " << requestId << " and type " << requestData.type;
|
||||||
m_dataTracker[ requestData.caller ][ requestData.type ] = m_dataTracker[ requestData.caller ][ requestData.type ] + 1;
|
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;
|
InfoRequestData* data = new InfoRequestData;
|
||||||
data->caller = requestData.caller;
|
data->caller = requestData.caller;
|
||||||
@@ -233,7 +233,7 @@ InfoSystemWorker::infoSlot( uint requestId, Tomahawk::InfoSystem::InfoRequestDat
|
|||||||
emit info( requestData, output );
|
emit info( requestData, output );
|
||||||
|
|
||||||
m_dataTracker[ requestData.caller ][ requestData.type ] = m_dataTracker[ requestData.caller ][ requestData.type ] - 1;
|
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 ];
|
delete m_savedRequestMap[ requestId ];
|
||||||
m_savedRequestMap.remove( requestId );
|
m_savedRequestMap.remove( requestId );
|
||||||
checkFinished( requestData.caller );
|
checkFinished( requestData.caller );
|
||||||
|
Reference in New Issue
Block a user