optimaze statistics::report() call

master
acetone 2022-11-21 09:31:36 +03:00
parent e0acac6328
commit 252b95432c
2 changed files with 18 additions and 28 deletions

View File

@ -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;

View File

@ -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;