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);
bool success = true;
beginTransaction();
beginWriteTransaction();
while (userVersion < opt.version) {
++userVersion;
@ -473,7 +473,7 @@ bool SqliteDb::createFtsTables(const MigrateOptions &opt)
bool success = true;
beginTransaction();
beginWriteTransaction();
for (const FtsTable &ftsTable : opt.ftsTables) {
beginSavepoint();
@ -592,7 +592,7 @@ bool SqliteDb::importDb(const MigrateOptions &opt, const QString &sourceFilePath
// Import Data
bool success = true;
beginTransaction();
beginWriteTransaction();
// Copy tables
if (opt.autoCopyTables) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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