diff --git a/src/persistence/db/plaindb.cpp b/src/persistence/db/plaindb.cpp index e08ebf1fa..1fec866c9 100644 --- a/src/persistence/db/plaindb.cpp +++ b/src/persistence/db/plaindb.cpp @@ -26,12 +26,14 @@ PlainDb::PlainDb(const QString &db_name, QList initList) { db = new QSqlDatabase(); *db = QSqlDatabase::addDatabase("QSQLITE"); + db->setConnectOptions("QSQLITE_ENABLE_SHARED_CACHE=1"); db->setDatabaseName(db_name); if (!db->open()) { qWarning() << QString("Can't open file: %1, history will not be saved!").arg(db_name); db->setDatabaseName(":memory:"); + db->setConnectOptions(); db->open(); } diff --git a/src/persistence/historykeeper.cpp b/src/persistence/historykeeper.cpp index 57e531176..ec21e8d56 100644 --- a/src/persistence/historykeeper.cpp +++ b/src/persistence/historykeeper.cpp @@ -36,9 +36,11 @@ #include "src/persistence/db/encrypteddb.h" static HistoryKeeper *historyInstance = nullptr; +QMutex HistoryKeeper::historyMutex; HistoryKeeper *HistoryKeeper::getInstance() { + historyMutex.lock(); if (historyInstance == nullptr) { QList initLst; @@ -67,6 +69,7 @@ HistoryKeeper *HistoryKeeper::getInstance() dbIntf = new PlainDb(path, initLst); historyInstance = new HistoryKeeper(dbIntf); } + historyMutex.unlock(); return historyInstance; } diff --git a/src/persistence/historykeeper.h b/src/persistence/historykeeper.h index c34e7e8e0..5fce5a447 100644 --- a/src/persistence/historykeeper.h +++ b/src/persistence/historykeeper.h @@ -24,6 +24,7 @@ #include #include #include +#include #include class GenericDdInterface; @@ -33,6 +34,7 @@ class HistoryKeeper { public: enum ChatType {ctSingle = 0, ctGroup}; + static QMutex historyMutex; struct HistMessage {