From 252b95432c2f206ddee706e144a3fdcd698107b9 Mon Sep 17 00:00:00 2001 From: acetone Date: Mon, 21 Nov 2022 09:31:36 +0300 Subject: [PATCH] optimaze statistics::report() call --- src/statistics.cpp | 45 ++++++++++++++++++--------------------------- src/statistics.h | 1 - 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/src/statistics.cpp b/src/statistics.cpp index 6d10a61..7596ce9 100644 --- a/src/statistics.cpp +++ b/src/statistics.cpp @@ -47,15 +47,25 @@ void Statistics::report(const LogEvent& event) return; } - { - DBManager db; - m_dailyDownload = db.incrementDailyDownloadTraffic(event.from); - m_dailyUpload = db.incrementDailyUploadTraffic(event.to); - m_totalDownload = db.incrementTotalDownloadTraffic(event.from); - m_totalUpload = db.incrementTotalUploadTraffic(event.to); - } + DBManager db; - addToDestinationsList(event.dest); + m_dailyDownload = db.incrementDailyDownloadTraffic(event.from); + m_dailyUpload = db.incrementDailyUploadTraffic(event.to); + m_totalDownload = db.incrementTotalDownloadTraffic(event.from); + m_totalUpload = db.incrementTotalUploadTraffic(event.to); + + db.incrementTotalTopCount(event.dest); + db.incrementDailyTopCount(event.dest); + + // editing without mutex because DBManager() already lock this place + if (not lastDestinations().contains(event.dest)) + { + if (lastDestinations().size() >= g::c::LAST_AND_TOP_LIST_SIZE) + { + m_lastDestinations.pop_back(); + } + m_lastDestinations.push_front(event.dest); + } m_cacheUpdatedAfterLastReport = false; } @@ -79,25 +89,6 @@ const TopDestinationList Statistics::totalTopDestinations() return m_totalTopDestinations; } -void Statistics::addToDestinationsList(const QString &dest) -{ - static QMutex mutex; - mutex.lock(); - if (not lastDestinations().contains(dest)) - { - if (lastDestinations().size() >= g::c::LAST_AND_TOP_LIST_SIZE) - { - m_lastDestinations.pop_back(); - } - m_lastDestinations.push_front(dest); - } - mutex.unlock(); - - DBManager db; - db.incrementTotalTopCount(dest); - db.incrementDailyTopCount(dest); -} - void Statistics::actualizeTopLists() { static QMutex mutex; diff --git a/src/statistics.h b/src/statistics.h index 876f52c..a9a15d1 100644 --- a/src/statistics.h +++ b/src/statistics.h @@ -48,7 +48,6 @@ public: static quint64 totalDownload() { return m_totalDownload; } private: - static void addToDestinationsList(const QString& dest); static void actualizeTopLists(); static QStringList m_lastDestinations;