From d2dba3b8c1b6e2631adb15f10427423173991aa6 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Thu, 13 May 2021 15:30:58 +0300 Subject: [PATCH] UI: SqliteDb: Add vacuum(). --- src/ui/3rdparty/sqlite/sqlitedb.cpp | 5 +++++ src/ui/3rdparty/sqlite/sqlitedb.h | 2 ++ src/ui/stat/statmanager.cpp | 6 +++--- src/ui/stat/statsql.cpp | 24 +++++++++++------------- src/ui/stat/statsql.h | 4 +--- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/ui/3rdparty/sqlite/sqlitedb.cpp b/src/ui/3rdparty/sqlite/sqlitedb.cpp index 361eced6..af1da0c1 100644 --- a/src/ui/3rdparty/sqlite/sqlitedb.cpp +++ b/src/ui/3rdparty/sqlite/sqlitedb.cpp @@ -96,6 +96,11 @@ bool SqliteDb::detach(const QString &schemaName) return ok; } +bool SqliteDb::vacuum() +{ + return execute("VACUUM;"); +} + bool SqliteDb::execute(const char *sql) { return sqlite3_exec(m_db, sql, nullptr, nullptr, nullptr) == SQLITE_OK; diff --git a/src/ui/3rdparty/sqlite/sqlitedb.h b/src/ui/3rdparty/sqlite/sqlitedb.h index 282b2a9c..7d761e13 100644 --- a/src/ui/3rdparty/sqlite/sqlitedb.h +++ b/src/ui/3rdparty/sqlite/sqlitedb.h @@ -51,6 +51,8 @@ public: bool attach(const QString &schemaName, const QString &filePath = QString()); bool detach(const QString &schemaName); + bool vacuum(); + bool execute(const char *sql); bool executeStr(const QString &sql); diff --git a/src/ui/stat/statmanager.cpp b/src/ui/stat/statmanager.cpp index 196d6551..f8d12e04 100644 --- a/src/ui/stat/statmanager.cpp +++ b/src/ui/stat/statmanager.cpp @@ -208,8 +208,8 @@ bool StatManager::updateTrafDay(qint64 unixTime) bool StatManager::clearTraffic() { sqliteDb()->beginTransaction(); - sqliteDb()->execute(StatSql::sqlClearTraffic); - sqliteDb()->execute(StatSql::sqlVacuum); + sqliteDb()->execute(StatSql::sqlDeleteAllTraffic); + sqliteDb()->vacuum(); sqliteDb()->commitTransaction(); clearAppIdCache(); @@ -410,7 +410,7 @@ bool StatManager::deleteConnAll() sqliteDb()->stmt(StatSql::sqlDeleteAllConnBlock) }, sqliteDb()->stmt(StatSql::sqlSelectDeletedAllConnAppList)); - sqliteDb()->execute(StatSql::sqlVacuum); + sqliteDb()->vacuum(); sqliteDb()->commitTransaction(); diff --git a/src/ui/stat/statsql.cpp b/src/ui/stat/statsql.cpp index 679ed493..c0c45b21 100644 --- a/src/ui/stat/statsql.cpp +++ b/src/ui/stat/statsql.cpp @@ -158,6 +158,17 @@ const char *const StatSql::sqlResetAppTrafTotals = "UPDATE traffic_app" " SET traf_time = ?1, in_bytes = 0, out_bytes = 0;"; +const char *const StatSql::sqlDeleteAllTraffic = + "DELETE FROM traffic_app;" + "DELETE FROM traffic_app_hour;" + "DELETE FROM traffic_app_day;" + "DELETE FROM traffic_app_month;" + "DELETE FROM traffic_hour;" + "DELETE FROM traffic_day;" + "DELETE FROM traffic_month;" + "DELETE FROM app WHERE (" + " SELECT 1 FROM conn c WHERE c.app_id = app.app_id LIMIT 1) IS NULL;"; + const char *const StatSql::sqlInsertConn = "INSERT INTO conn(app_id, conn_time, process_id, inbound, blocked," " ip_proto, local_port, remote_port, local_ip, remote_ip)" @@ -191,16 +202,3 @@ const char *const StatSql::sqlSelectDeletedAllConnAppList = "SELECT t.app_id, t.path FROM app t" " LEFT JOIN traffic_app ta ON ta.app_id = t.app_id" " WHERE ta.app_id IS NULL;"; - -const char *const StatSql::sqlClearTraffic = - "DELETE FROM traffic_app;" - "DELETE FROM traffic_app_hour;" - "DELETE FROM traffic_app_day;" - "DELETE FROM traffic_app_month;" - "DELETE FROM traffic_hour;" - "DELETE FROM traffic_day;" - "DELETE FROM traffic_month;" - "DELETE FROM app WHERE (" - " SELECT 1 FROM conn c WHERE c.app_id = app.app_id LIMIT 1) IS NULL;"; - -const char *const StatSql::sqlVacuum = "VACUUM;"; diff --git a/src/ui/stat/statsql.h b/src/ui/stat/statsql.h index 457f48d4..c290f7f5 100644 --- a/src/ui/stat/statsql.h +++ b/src/ui/stat/statsql.h @@ -66,6 +66,7 @@ public: static const char *const sqlSelectDeletedStatAppList; static const char *const sqlResetAppTrafTotals; + static const char *const sqlDeleteAllTraffic; static const char *const sqlInsertConn; static const char *const sqlInsertConnBlock; @@ -79,9 +80,6 @@ public: static const char *const sqlDeleteAllConn; static const char *const sqlDeleteAllConnBlock; static const char *const sqlSelectDeletedAllConnAppList; - - static const char *const sqlClearTraffic; - static const char *const sqlVacuum; }; #endif // STATSQL_H