From 237c7a87d0c37d2a4e7683c460960547c59b30b9 Mon Sep 17 00:00:00 2001 From: acetone Date: Tue, 22 Nov 2022 11:05:42 +0300 Subject: [PATCH] little optimization --- src/g.cpp | 1 + src/g.h | 1 + src/html/index.html | 2 +- src/webpage.cpp | 37 ++++++++++++++++++++++++++----------- src/webpage.h | 2 +- 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/g.cpp b/src/g.cpp index fd12253..227cd98 100644 --- a/src/g.cpp +++ b/src/g.cpp @@ -48,6 +48,7 @@ namespace c { const QString HA_LAST_DESTINATIONS_LIST = "{{LAST_DESTINATIONS_LIST}}"; const QString HA_DAILY_TOP_DESTINATIONS_LIST = "{{DAILY_TOP_DESTINATIONS_LIST}}"; const QString HA_TOTAL_TOP_DESTINATIONS_LIST = "{{TOTAL_TOP_DESTINATIONS_LIST}}"; + const QString HA_TOP_MEASURE = "{{TOP_MEASURE}}"; const QString HA_BLOCKED_DESTINTIONS = "{{BLOCKED_DESTINATIONS}}"; const QString HA_INFORMATION = "{{INFORMATION}}"; const QString HA_COPYRIGHT = "{{COPYRIGHT}}"; diff --git a/src/g.h b/src/g.h index 96466f6..1ae4c59 100644 --- a/src/g.h +++ b/src/g.h @@ -50,6 +50,7 @@ namespace c /* for Constants */ { extern const QString HA_LAST_DESTINATIONS_LIST; extern const QString HA_DAILY_TOP_DESTINATIONS_LIST; extern const QString HA_TOTAL_TOP_DESTINATIONS_LIST; + extern const QString HA_TOP_MEASURE; extern const QString HA_BLOCKED_DESTINTIONS; extern const QString HA_INFORMATION; extern const QString HA_COPYRIGHT; diff --git a/src/html/index.html b/src/html/index.html index 8b5c69a..bf2e59e 100644 --- a/src/html/index.html +++ b/src/html/index.html @@ -99,7 +99,7 @@ {{INFORMATION}}
- Top destinations + Top {{TOP_MEASURE}}
diff --git a/src/webpage.cpp b/src/webpage.cpp index 2225cde..5a3062e 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -84,8 +84,8 @@ const QString WebPage::m_informationBlock = "\ struct HumanReadableValue { - QString integer = "NaN"; - QString decimal = "0"; + QString integer = "3"; + QString decimal = "5"; QString measure = "anon"; }; @@ -108,7 +108,7 @@ QByteArray WebPage::document() topDestinations(page); blockedDestinations(page); informationBlock(page); - copyright(page); + footer(page); return page.toUtf8(); } @@ -126,28 +126,41 @@ void WebPage::customStyles(QString &document) void WebPage::lastDestinations(QString &document) { - QStringList dests = Statistics::lastDestinations(); - QString destinationsBlock; static QStringList allBlockedDestinations; - for (const auto& dest: dests) + static bool inited = false; + if (not inited) { - bool blocked = false; + inited = true; for (const auto& inst: g::instanses) { QMapIterator mIter(inst.second->blackList()); while (mIter.hasNext()) { mIter.next(); - if (mIter.key() == dest or mIter.value().contains(dest)) + if (not allBlockedDestinations.contains(mIter.key())) { - blocked = true; - break; + allBlockedDestinations.push_back(mIter.key()); + } + for (const auto& addr: mIter.value()) + { + if (not allBlockedDestinations.contains(addr)) + { + allBlockedDestinations.push_back(addr); + } } } } + } + QStringList dests = Statistics::lastDestinations(); + QString destinationsBlock; + + for (const auto& dest: dests) + { + bool blocked = allBlockedDestinations.contains(dest); destinationsBlock += blocked ? lastDestinationItemBlocked(dest) : lastDestinationItemAllowed(dest); } + document.replace(g::c::HA_LAST_DESTINATIONS_LIST, destinationsBlock); } @@ -172,6 +185,8 @@ void WebPage::trafficBlock(QString &document) void WebPage::topDestinations(QString &document) { + document.replace(g::c::HA_TOP_MEASURE, g::p::IGNORE_IP_ADDRS_IN_STATISTCS ? "domains" : "destinations"); + QString dailyTopList; for (const auto& dTop: Statistics::dailyTopDestinations()) { @@ -263,7 +278,7 @@ void WebPage::informationBlock(QString &document) document.replace(g::c::HA_INFORMATION, "\n"+infoBlock); } -void WebPage::copyright(QString &document) +void WebPage::footer(QString &document) { document.replace(g::c::HA_COPYRIGHT, g::c::COPYRIGHT); document.replace(g::c::HA_VERSION, g::c::SOFTWARE_VERSION); diff --git a/src/webpage.h b/src/webpage.h index 6f91cd3..af59d45 100644 --- a/src/webpage.h +++ b/src/webpage.h @@ -38,7 +38,7 @@ private: static void topDestinations(QString& document); static void blockedDestinations(QString& document); static void informationBlock(QString& document); - static void copyright(QString& document); + static void footer(QString& document); static QString lastDestinationItemAllowed(const QString& destination); static QString lastDestinationItemBlocked(const QString& destination);