diff --git a/src/tests/db/test.cpp b/src/tests/db/test.cpp index 149adcb3..2e52eea8 100644 --- a/src/tests/db/test.cpp +++ b/src/tests/db/test.cpp @@ -102,11 +102,11 @@ void Test::debugStatTraf(SqliteDb *sqliteDb) debugStatTrafStep(sqliteDb, "traffic_app_total", "SELECT app_id, traf_time, in_bytes, out_bytes" - " FROM app;", 1); + " FROM app;"); } void Test::debugStatTrafStep(SqliteDb *sqliteDb, const char *name, - const char *sql, int timeMult) + const char *sql) { SqliteStmt stmt; @@ -114,7 +114,7 @@ void Test::debugStatTrafStep(SqliteDb *sqliteDb, const char *name, qDebug() << '>' << name << '<'; while (stmt.step() == SqliteStmt::StepRow) { - const qint64 trafTime = stmt.columnInt64(1) * timeMult; + const qint64 trafTime = stmt.columnInt64(1) * 3600; qDebug() << '>' << stmt.columnInt64(0) diff --git a/src/tests/db/test.h b/src/tests/db/test.h index 1028cd2b..ed22a2b8 100644 --- a/src/tests/db/test.h +++ b/src/tests/db/test.h @@ -17,7 +17,7 @@ private: void debugStatTraf(SqliteDb *sqliteDb); void debugStatTrafStep(SqliteDb *sqliteDb, const char *name, - const char *sql, int timeMult = 3600); + const char *sql); }; #endif // TEST_H diff --git a/src/ui/db/databasemanager.cpp b/src/ui/db/databasemanager.cpp index df17c369..de8a0046 100644 --- a/src/ui/db/databasemanager.cpp +++ b/src/ui/db/databasemanager.cpp @@ -75,6 +75,8 @@ void DatabaseManager::logStatTraf(quint16 procCount, const quint8 *procBits, m_lastTrafDay = trafDay; m_lastTrafMonth = trafMonth; + m_sqliteDb->beginTransaction(); + // Insert Statemets QStmtList insertTrafAppStmts = QStmtList() << getTrafficStmt(DatabaseSql::sqlInsertTrafficAppHour, trafHour) @@ -99,8 +101,6 @@ void DatabaseManager::logStatTraf(quint16 procCount, const quint8 *procBits, << getTrafficStmt(DatabaseSql::sqlUpdateTrafficDay, trafDay) << getTrafficStmt(DatabaseSql::sqlUpdateTrafficMonth, trafMonth); - m_sqliteDb->beginTransaction(); - for (quint16 i = 0; i < procCount; ++i) { const bool active = procBits[i / 8] & (1 << (i & 7)); if (!active) { @@ -174,6 +174,8 @@ qint64 DatabaseManager::createAppId(const QString &appPath) { qint64 appId = 0; + m_sqliteDb->beginTransaction(); + SqliteStmt *stmt = getSqliteStmt(DatabaseSql::sqlInsertAppId); const qint64 unixTime = DateUtil::getUnixTime(); @@ -186,6 +188,8 @@ qint64 DatabaseManager::createAppId(const QString &appPath) } stmt->reset(); + m_sqliteDb->commitTransaction(); + return appId; } diff --git a/src/ui/log/model/traflistmodel.cpp b/src/ui/log/model/traflistmodel.cpp index c1a0a7f8..9ddcdb00 100644 --- a/src/ui/log/model/traflistmodel.cpp +++ b/src/ui/log/model/traflistmodel.cpp @@ -60,15 +60,7 @@ QVariant TrafListModel::data(const QModelIndex &index, int role) const const int row = index.row(); if (!m_rowCache.isValid(row)) { - m_rowCache.row = row; - m_rowCache.trafTime = getTrafTime(row); - - const char *sqlSelectTraffic = getSqlSelectTraffic(m_type, m_appId); - - m_databaseManager->getTraffic( - sqlSelectTraffic, m_rowCache.trafTime, - m_rowCache.inBytes, m_rowCache.outBytes, - m_appId); + updateRowCache(row); } switch (role) { @@ -97,6 +89,19 @@ void TrafListModel::clear() { } +void TrafListModel::updateRowCache(int row) const +{ + m_rowCache.row = row; + m_rowCache.trafTime = getTrafTime(row); + + const char *sqlSelectTraffic = getSqlSelectTraffic(m_type, m_appId); + + m_databaseManager->getTraffic( + sqlSelectTraffic, m_rowCache.trafTime, + m_rowCache.inBytes, m_rowCache.outBytes, + m_appId); +} + QString TrafListModel::formatTrafTime(qint32 trafTime) const { const qint64 unixTime = DateUtil::toUnixTime(trafTime); diff --git a/src/ui/log/model/traflistmodel.h b/src/ui/log/model/traflistmodel.h index 1edcd9b9..90e0b1ef 100644 --- a/src/ui/log/model/traflistmodel.h +++ b/src/ui/log/model/traflistmodel.h @@ -57,6 +57,8 @@ public slots: void clear(); private: + void updateRowCache(int row) const; + QString formatTrafTime(qint32 trafTime) const; qint32 getTrafTime(int row) const; diff --git a/src/ui/translationmanager.cpp b/src/ui/translationmanager.cpp index ce3fb418..09e3e07e 100644 --- a/src/ui/translationmanager.cpp +++ b/src/ui/translationmanager.cpp @@ -23,7 +23,7 @@ TranslationManager::~TranslationManager() TranslationManager *TranslationManager::instance() { - static TranslationManager *g_instanceTranslationManager = 0; + static TranslationManager *g_instanceTranslationManager = nullptr; if (!g_instanceTranslationManager) { g_instanceTranslationManager = new TranslationManager();