mirror of https://github.com/KDE/kasts.git
Set database to WAL mode on startup
Using WAL mode avoids having to lock the database for certain transactions. Therefore, deadlocks between read/writes from different threads should not happen anymore. These were rare, but happened sometimes on slower hardware or slow storage devices. BUG: 465110
This commit is contained in:
parent
6e998d608c
commit
c5f4fd23fc
|
@ -47,6 +47,8 @@ void Database::closeDatabase(const QString &connectionName)
|
|||
|
||||
bool Database::migrate()
|
||||
{
|
||||
setWalMode();
|
||||
|
||||
int dbversion = version();
|
||||
if (dbversion < 1)
|
||||
TRUE_OR_RETURN(migrateTo1());
|
||||
|
@ -200,6 +202,26 @@ int Database::version()
|
|||
return -1;
|
||||
}
|
||||
|
||||
void Database::setWalMode()
|
||||
{
|
||||
bool ok = false;
|
||||
QSqlQuery query;
|
||||
query.prepare(QStringLiteral("PRAGMA journal_mode;"));
|
||||
execute(query);
|
||||
if (query.next()) {
|
||||
ok = (query.value(0).toString() == QStringLiteral("wal"));
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
query.prepare(QStringLiteral("PRAGMA journal_mode=WAL;"));
|
||||
execute(query);
|
||||
if (query.next()) {
|
||||
ok = (query.value(0).toString() == QStringLiteral("wal"));
|
||||
}
|
||||
qDebug() << "Activating WAL mode on database:" << (ok ? "ok" : "not ok!");
|
||||
}
|
||||
}
|
||||
|
||||
void Database::cleanup()
|
||||
{
|
||||
// TODO: create database sanity checks, or, alternatively, create database scrub routine
|
||||
|
|
|
@ -43,6 +43,7 @@ private:
|
|||
bool migrateTo5();
|
||||
bool migrateTo6();
|
||||
void cleanup();
|
||||
void setWalMode();
|
||||
|
||||
inline static const QString m_dbName = QStringLiteral("database.db3");
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue