Switch sqlite db to WAL mode
This commit is contained in:
父節點
1e06ec5d69
當前提交
6640504b49
@ -630,6 +630,8 @@ void MainWindow::saveSettings()
|
|||||||
"Failed to remove old database. Settings not saved.");
|
"Failed to remove old database. Settings not saved.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
QFile::remove(Common::databasePath() + "-shm");
|
||||||
|
QFile::remove(Common::databasePath() + "-wal");
|
||||||
}
|
}
|
||||||
|
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
#include <QSqlQuery>
|
||||||
#include "databasefactory.h"
|
#include "databasefactory.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "looqsgeneralexception.h"
|
#include "looqsgeneralexception.h"
|
||||||
@ -31,11 +32,23 @@ QSqlDatabase DatabaseFactory::forCurrentThread()
|
|||||||
QSqlDatabase db =
|
QSqlDatabase db =
|
||||||
QSqlDatabase::addDatabase("QSQLITE", "LOOQS" + QString::number((quint64)QThread::currentThread(), 16));
|
QSqlDatabase::addDatabase("QSQLITE", "LOOQS" + QString::number((quint64)QThread::currentThread(), 16));
|
||||||
db.setDatabaseName(this->connectionString);
|
db.setDatabaseName(this->connectionString);
|
||||||
|
db.setConnectOptions("QSQLITE_BUSY_TIMEOUT=30000");
|
||||||
if(!db.open())
|
if(!db.open())
|
||||||
{
|
{
|
||||||
Logger::error() << "Failed to open the database: " << this->connectionString << Qt::endl;
|
Logger::error() << "Failed to open the database: " << this->connectionString << Qt::endl;
|
||||||
throw LooqsGeneralException("Failed to create open new connection");
|
throw LooqsGeneralException("Failed to create open new connection");
|
||||||
}
|
}
|
||||||
|
QSqlQuery q(db);
|
||||||
|
if(!q.exec("PRAGMA journal_mode=WAL;"))
|
||||||
|
{
|
||||||
|
Logger::error() << "Failed to set WAL mode: " << this->connectionString << Qt::endl;
|
||||||
|
throw LooqsGeneralException("Failed to set WAL mode on sqlite database");
|
||||||
|
}
|
||||||
|
if(!q.exec("PRAGMA wal_autocheckpoint=250;"))
|
||||||
|
{
|
||||||
|
Logger::error() << "Failed to set WAL autocheckpoint: " << this->connectionString << Qt::endl;
|
||||||
|
throw LooqsGeneralException("Failed to set WAL autocheckpoint on sqlite database");
|
||||||
|
}
|
||||||
dbStore.setLocalData(db);
|
dbStore.setLocalData(db);
|
||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user