UI: SqliteDb: Use "Immediate Transaction" for writes

This commit is contained in:
Nodir Temirkhodjaev 2024-02-17 17:44:35 +03:00
parent 00d28feaf7
commit 2560f2e503
8 changed files with 32 additions and 14 deletions

View File

@ -395,7 +395,7 @@ bool SqliteDb::migrateSqlScripts(const MigrateOptions &opt, int userVersion, boo
const QDir dir(opt.sqlDir); const QDir dir(opt.sqlDir);
bool success = true; bool success = true;
beginTransaction(); beginWriteTransaction();
while (userVersion < opt.version) { while (userVersion < opt.version) {
++userVersion; ++userVersion;
@ -473,7 +473,7 @@ bool SqliteDb::createFtsTables(const MigrateOptions &opt)
bool success = true; bool success = true;
beginTransaction(); beginWriteTransaction();
for (const FtsTable &ftsTable : opt.ftsTables) { for (const FtsTable &ftsTable : opt.ftsTables) {
beginSavepoint(); beginSavepoint();
@ -592,7 +592,7 @@ bool SqliteDb::importDb(const MigrateOptions &opt, const QString &sourceFilePath
// Import Data // Import Data
bool success = true; bool success = true;
beginTransaction(); beginWriteTransaction();
// Copy tables // Copy tables
if (opt.autoCopyTables) { if (opt.autoCopyTables) {

View File

@ -220,7 +220,7 @@ bool AppInfoManager::saveToDb(const QString &appPath, AppInfo &appInfo, const QI
bool ok = true; bool ok = true;
sqliteDb()->beginTransaction(); sqliteDb()->beginWriteTransaction();
// Save icon image // Save icon image
QVariant iconId; QVariant iconId;
@ -299,7 +299,7 @@ bool AppInfoManager::deleteAppsAndIcons(
{ {
bool ok = false; bool ok = false;
sqliteDb()->beginTransaction(); sqliteDb()->beginWriteTransaction();
// Delete old icons // Delete old icons
deleteIcons(iconIds, ok); deleteIcons(iconIds, ok);

View File

@ -665,7 +665,7 @@ bool ConfAppManager::updateDriverUpdateAppConf(const App &app)
bool ConfAppManager::beginTransaction() bool ConfAppManager::beginTransaction()
{ {
return sqliteDb()->beginTransaction(); return sqliteDb()->beginWriteTransaction();
} }
void ConfAppManager::commitTransaction(bool &ok) void ConfAppManager::commitTransaction(bool &ok)

View File

@ -955,7 +955,7 @@ bool ConfManager::saveTask(TaskInfo *taskInfo)
bool ConfManager::beginTransaction() bool ConfManager::beginTransaction()
{ {
return sqliteDb()->beginTransaction(); return sqliteDb()->beginWriteTransaction();
} }
void ConfManager::commitTransaction(bool &ok) void ConfManager::commitTransaction(bool &ok)

View File

@ -210,7 +210,7 @@ bool ConfRuleManager::updateDriverRuleFlag(int ruleId, bool enabled)
bool ConfRuleManager::beginTransaction() bool ConfRuleManager::beginTransaction()
{ {
return sqliteDb()->beginTransaction(); return sqliteDb()->beginWriteTransaction();
} }
void ConfRuleManager::commitTransaction(bool &ok) void ConfRuleManager::commitTransaction(bool &ok)

View File

@ -253,7 +253,7 @@ bool ConfZoneManager::updateDriverZoneFlag(int zoneId, bool enabled)
bool ConfZoneManager::beginTransaction() bool ConfZoneManager::beginTransaction()
{ {
return sqliteDb()->beginTransaction(); return sqliteDb()->beginWriteTransaction();
} }
void ConfZoneManager::commitTransaction(bool &ok) void ConfZoneManager::commitTransaction(bool &ok)

View File

@ -166,9 +166,14 @@ bool StatManager::updateTrafDay(qint64 unixTime)
bool StatManager::clearTraffic() bool StatManager::clearTraffic()
{ {
sqliteDb()->beginTransaction(); bool ok = true;
sqliteDb()->execute(StatSql::sqlDeleteAllTraffic);
sqliteDb()->commitTransaction(); beginTransaction();
ok = sqliteDb()->execute(StatSql::sqlDeleteAllTraffic);
commitTransaction(ok);
if (!ok)
return false;
sqliteDb()->vacuum(); // Vacuum outside of transaction sqliteDb()->vacuum(); // Vacuum outside of transaction
@ -256,7 +261,7 @@ bool StatManager::logStatTraf(const LogEntryStatTraf &entry, qint64 unixTime)
const bool isNewDay = updateTrafDay(unixTime); const bool isNewDay = updateTrafDay(unixTime);
sqliteDb()->beginTransaction(); sqliteDb()->beginWriteTransaction();
// Delete old data // Delete old data
if (isNewDay) { if (isNewDay) {
@ -328,7 +333,7 @@ bool StatManager::logStatTraf(const LogEntryStatTraf &entry, qint64 unixTime)
bool StatManager::deleteStatApp(qint64 appId) bool StatManager::deleteStatApp(qint64 appId)
{ {
sqliteDb()->beginTransaction(); sqliteDb()->beginWriteTransaction();
SqliteStmt::doList({ getIdStmt(StatSql::sqlDeleteAppTrafHour, appId), SqliteStmt::doList({ getIdStmt(StatSql::sqlDeleteAppTrafHour, appId),
getIdStmt(StatSql::sqlDeleteAppTrafDay, appId), getIdStmt(StatSql::sqlDeleteAppTrafDay, appId),
@ -599,3 +604,13 @@ SqliteStmt *StatManager::getIdStmt(const char *sql, qint64 id)
return stmt; return stmt;
} }
bool StatManager::beginTransaction()
{
return sqliteDb()->beginWriteTransaction();
}
void StatManager::commitTransaction(bool &ok)
{
ok = sqliteDb()->endTransaction(ok);
}

View File

@ -106,6 +106,9 @@ private:
SqliteStmt *getTrafficStmt(const char *sql, qint32 trafTime); SqliteStmt *getTrafficStmt(const char *sql, qint32 trafTime);
SqliteStmt *getIdStmt(const char *sql, qint64 id); SqliteStmt *getIdStmt(const char *sql, qint64 id);
bool beginTransaction();
void commitTransaction(bool &ok);
private: private:
bool m_isActivePeriodSet : 1 = false; bool m_isActivePeriodSet : 1 = false;
bool m_isActivePeriod : 1 = false; bool m_isActivePeriod : 1 = false;