little optimization
This commit is contained in:
@@ -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}}";
|
||||
|
||||
@@ -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;
|
||||
|
||||
+1
-1
@@ -99,7 +99,7 @@
|
||||
</section>{{INFORMATION}}
|
||||
<section class="proxyService__topDestinations topDestinations section">
|
||||
<div class="section__title">
|
||||
Top destinations
|
||||
Top {{TOP_MEASURE}}
|
||||
</div>
|
||||
<div class="topDestinations__block">
|
||||
<div class="topDestinations__title">
|
||||
|
||||
+26
-11
@@ -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<QString, QStringList> 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);
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user