mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-03-25 02:09:48 +01:00
Add sync timer to cache to avoid saving everything at shutdown (runs
once a minute)
This commit is contained in:
parent
ed93084315
commit
43834a17bc
@ -32,7 +32,8 @@ namespace InfoSystem
|
||||
|
||||
|
||||
InfoSystemCache::InfoSystemCache( QObject* parent )
|
||||
: QObject(parent)
|
||||
: QObject( parent )
|
||||
, m_syncTimer( this )
|
||||
, m_cacheRemainingToLoad( 0 )
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
@ -49,6 +50,9 @@ InfoSystemCache::InfoSystemCache( QObject* parent )
|
||||
QMetaObject::invokeMethod( this, "loadCache", Qt::QueuedConnection, Q_ARG( Tomahawk::InfoSystem::InfoType, type ), Q_ARG( QString, cacheFile ) );
|
||||
}
|
||||
}
|
||||
m_syncTimer.setInterval( 60000 );
|
||||
m_syncTimer.setSingleShot( false );
|
||||
connect( &m_syncTimer, SIGNAL( timeout() ), SLOT( syncTimerFired() ) );
|
||||
}
|
||||
|
||||
|
||||
@ -69,6 +73,27 @@ InfoSystemCache::~InfoSystemCache()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
InfoSystemCache::syncTimerFired()
|
||||
{
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
if ( m_cacheRemainingToLoad > 0 )
|
||||
return;
|
||||
|
||||
qDebug() << "Syncing infosystemcache to disk";
|
||||
QString cacheBaseDir = QDesktopServices::storageLocation( QDesktopServices::CacheLocation );
|
||||
for ( int i = 0; i <= InfoNoInfo; i++ )
|
||||
{
|
||||
InfoType type = (InfoType)(i);
|
||||
if ( m_dirtySet.contains( type ) && m_dataCache.contains( type ) )
|
||||
{
|
||||
QString cacheDir = cacheBaseDir + "/InfoSystemCache/" + QString::number( i );
|
||||
saveCache( type, cacheDir );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
InfoSystemCache::getCachedInfoSlot( Tomahawk::InfoSystem::InfoCriteriaHash criteria, qint64 newMaxAge, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData )
|
||||
{
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <QDateTime>
|
||||
#include <QObject>
|
||||
#include <QtDebug>
|
||||
#include <QTimer>
|
||||
|
||||
#include "infosystem.h"
|
||||
|
||||
@ -49,6 +50,7 @@ public slots:
|
||||
void updateCacheSlot( Tomahawk::InfoSystem::InfoCriteriaHash criteria, qint64 maxAge, Tomahawk::InfoSystem::InfoType type, QVariant output );
|
||||
|
||||
private slots:
|
||||
void syncTimerFired();
|
||||
void loadCache( Tomahawk::InfoSystem::InfoType type, const QString &cacheFile );
|
||||
void saveCache( Tomahawk::InfoSystem::InfoType type, const QString &cacheDir );
|
||||
|
||||
@ -57,6 +59,7 @@ private:
|
||||
QHash< InfoType, QHash< InfoCriteriaHash, QDateTime > > m_insertTimeCache;
|
||||
QHash< InfoType, QHash< InfoCriteriaHash, QDateTime > > m_maxTimeCache;
|
||||
QSet< InfoType > m_dirtySet;
|
||||
QTimer m_syncTimer;
|
||||
int m_cacheRemainingToLoad;
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user