cache: save disk cache index on a regular interval in case of crashing
DiskManager tries to keep track of all files made across sessions in an index, but the index was only saved on close. This meant if the program crashed (not an uncommon occurrence at the moment), it would "forget" about any files it had made that session.
This commit is contained in:
@@ -67,6 +67,7 @@ void Config::SetDefaults()
|
||||
SetEntryInternal(QStringLiteral("HoverFocus"), NodeParam::kBoolean, false);
|
||||
SetEntryInternal(QStringLiteral("AudioScrubbing"), NodeParam::kBoolean, true);
|
||||
SetEntryInternal(QStringLiteral("AutorecoveryInterval"), NodeParam::kInt, 1);
|
||||
SetEntryInternal(QStringLiteral("DiskCacheSaveInterval"), NodeParam::kInt, 10000);
|
||||
SetEntryInternal(QStringLiteral("Language"), NodeParam::kString, QLocale::system().name());
|
||||
SetEntryInternal(QStringLiteral("ScrollZooms"), NodeParam::kBoolean, false);
|
||||
SetEntryInternal(QStringLiteral("EnableSeekToImport"), NodeParam::kBoolean, false);
|
||||
|
||||
@@ -189,6 +189,10 @@ DiskCacheFolder::DiskCacheFolder(const QString &path, QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
SetPath(path);
|
||||
|
||||
save_timer_.setInterval(Config::Current()[QStringLiteral("DiskCacheSaveInterval")].toInt());
|
||||
connect(&save_timer_, &QTimer::timeout, this, &DiskCacheFolder::SaveDiskCacheIndex);
|
||||
save_timer_.start();
|
||||
}
|
||||
|
||||
DiskCacheFolder::~DiskCacheFolder()
|
||||
@@ -335,6 +339,11 @@ void DiskCacheFolder::CloseCacheFolder()
|
||||
}
|
||||
|
||||
// Save current cache index
|
||||
SaveDiskCacheIndex();
|
||||
}
|
||||
|
||||
void DiskCacheFolder::SaveDiskCacheIndex()
|
||||
{
|
||||
QFile cache_index_file(index_path_);
|
||||
|
||||
if (cache_index_file.open(QFile::WriteOnly)) {
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include <QMap>
|
||||
#include <QMutex>
|
||||
#include <QObject>
|
||||
#include <QTimer>
|
||||
|
||||
#include "common/define.h"
|
||||
#include "project/project.h"
|
||||
@@ -97,6 +98,11 @@ private:
|
||||
|
||||
bool clear_on_close_;
|
||||
|
||||
QTimer save_timer_;
|
||||
|
||||
private slots:
|
||||
void SaveDiskCacheIndex();
|
||||
|
||||
};
|
||||
|
||||
class DiskManager : public QObject
|
||||
|
||||
Reference in New Issue
Block a user