mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-07-31 11:20:22 +02:00
Add sync timer to cache to avoid saving everything at shutdown (runs
once a minute)
This commit is contained in:
@@ -32,7 +32,8 @@ namespace InfoSystem
|
|||||||
|
|
||||||
|
|
||||||
InfoSystemCache::InfoSystemCache( QObject* parent )
|
InfoSystemCache::InfoSystemCache( QObject* parent )
|
||||||
: QObject(parent)
|
: QObject( parent )
|
||||||
|
, m_syncTimer( this )
|
||||||
, m_cacheRemainingToLoad( 0 )
|
, m_cacheRemainingToLoad( 0 )
|
||||||
{
|
{
|
||||||
qDebug() << Q_FUNC_INFO;
|
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 ) );
|
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
|
void
|
||||||
InfoSystemCache::getCachedInfoSlot( Tomahawk::InfoSystem::InfoCriteriaHash criteria, qint64 newMaxAge, QString caller, Tomahawk::InfoSystem::InfoType type, QVariant input, Tomahawk::InfoSystem::InfoCustomData customData )
|
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 <QDateTime>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include "infosystem.h"
|
#include "infosystem.h"
|
||||||
|
|
||||||
@@ -49,6 +50,7 @@ public slots:
|
|||||||
void updateCacheSlot( Tomahawk::InfoSystem::InfoCriteriaHash criteria, qint64 maxAge, Tomahawk::InfoSystem::InfoType type, QVariant output );
|
void updateCacheSlot( Tomahawk::InfoSystem::InfoCriteriaHash criteria, qint64 maxAge, Tomahawk::InfoSystem::InfoType type, QVariant output );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
void syncTimerFired();
|
||||||
void loadCache( Tomahawk::InfoSystem::InfoType type, const QString &cacheFile );
|
void loadCache( Tomahawk::InfoSystem::InfoType type, const QString &cacheFile );
|
||||||
void saveCache( Tomahawk::InfoSystem::InfoType type, const QString &cacheDir );
|
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_insertTimeCache;
|
||||||
QHash< InfoType, QHash< InfoCriteriaHash, QDateTime > > m_maxTimeCache;
|
QHash< InfoType, QHash< InfoCriteriaHash, QDateTime > > m_maxTimeCache;
|
||||||
QSet< InfoType > m_dirtySet;
|
QSet< InfoType > m_dirtySet;
|
||||||
|
QTimer m_syncTimer;
|
||||||
int m_cacheRemainingToLoad;
|
int m_cacheRemainingToLoad;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user