优化url统计过滤逻辑。
This commit is contained in:
parent
b1c83bf58f
commit
850d143366
@ -79,20 +79,25 @@ void visitAnalysis() {
|
||||
std::string url;
|
||||
if (root.contains("url")) {
|
||||
url = root["url"].as_string();
|
||||
}
|
||||
auto database = Singleton<Older::Database>::instance();
|
||||
if (std::filesystem::exists("amass_blog" + url) && (url.find("/我的博客/page") != 0)) {
|
||||
if (url.size() > 1 && url.back() == '/') {
|
||||
if (!url.empty() && (url.back() == '/')) {
|
||||
url.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
if (root.contains("visitor_uuid") && root.contains("user_agent")) {
|
||||
auto timestamp = duration_cast<seconds>(system_clock::now().time_since_epoch());
|
||||
auto visitorUuid = std::string(root["visitor_uuid"].as_string());
|
||||
auto userAgent = std::string(root["user_agent"].as_string());
|
||||
database->upsertVisitRecord(url, visitorUuid, userAgent, timestamp.count());
|
||||
auto database = Singleton<Older::Database>::instance();
|
||||
auto settings = Singleton<Older::Settings>::instance();
|
||||
auto documentRoot = settings->documentRoot();
|
||||
if (!url.empty() && (documentRoot.empty() || std::filesystem::exists(documentRoot + url))) {
|
||||
if (url.find("/我的博客/page") != 0) { // Docusaurus 这个路径过滤掉
|
||||
if (root.contains("visitor_uuid") && root.contains("user_agent")) {
|
||||
auto timestamp = duration_cast<seconds>(system_clock::now().time_since_epoch());
|
||||
auto visitorUuid = std::string(root["visitor_uuid"].as_string());
|
||||
auto userAgent = std::string(root["user_agent"].as_string());
|
||||
database->upsertVisitRecord(url, visitorUuid, userAgent, timestamp.count());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto urlStats = database->visitorStats(url);
|
||||
auto siteStats = database->siteStats();
|
||||
|
||||
|
49
Settings.cpp
49
Settings.cpp
@ -1,6 +1,49 @@
|
||||
#include "Settings.h"
|
||||
#include "Core/Logger.h"
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/xml_parser.hpp>
|
||||
#include <filesystem>
|
||||
#include <thread>
|
||||
|
||||
constexpr auto SettingsFilePath = "settings.xml";
|
||||
|
||||
namespace Older {
|
||||
Settings::Settings() {
|
||||
if (!std::filesystem::exists(SettingsFilePath)) {
|
||||
save();
|
||||
}
|
||||
load();
|
||||
}
|
||||
|
||||
void Settings::save() {
|
||||
using namespace boost::property_tree;
|
||||
ptree ptree;
|
||||
ptree.put("Application.Threads", std::thread::hardware_concurrency());
|
||||
ptree.put("Application.SqlitePath", m_sqlitePath);
|
||||
|
||||
ptree.put("Application.HttpServer.Address", m_server);
|
||||
ptree.put("Application.HttpServer.DocumentRoot", m_documentRoot);
|
||||
ptree.put("Application.HttpServer.DocumentRoot.<xmlcomment>", "静态网页文件存放位置,为空时网站统计将不判断页面页面是否存在");
|
||||
|
||||
xml_writer_settings<std::string> settings('\t', 1);
|
||||
write_xml(SettingsFilePath, ptree, std::locale(), settings);
|
||||
}
|
||||
|
||||
void Settings::load() {
|
||||
using namespace boost::property_tree;
|
||||
ptree ptree;
|
||||
try {
|
||||
read_xml(SettingsFilePath, ptree);
|
||||
m_sqlitePath = ptree.get<std::string>("Application.SqlitePath");
|
||||
m_threads = ptree.get<uint32_t>("Application.Threads");
|
||||
|
||||
m_server = ptree.get<std::string>("Application.HttpServer.Address");
|
||||
m_documentRoot = ptree.get<std::string>("Application.HttpServer.DocumentRoot");
|
||||
} catch (const xml_parser_error &error) {
|
||||
LOG(error) << "parse " << SettingsFilePath << " failed: " << error.message();
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t Settings::threads() const {
|
||||
return m_threads;
|
||||
}
|
||||
@ -13,11 +56,15 @@ uint16_t Settings::port() const {
|
||||
return m_port;
|
||||
}
|
||||
|
||||
std::string Settings::documentRoot() const {
|
||||
return m_documentRoot;
|
||||
}
|
||||
|
||||
std::string Settings::live2dModelsRoot() const {
|
||||
return m_live2dModelsRoot;
|
||||
}
|
||||
|
||||
std::string Settings::sqlitePath() const{
|
||||
std::string Settings::sqlitePath() const {
|
||||
return m_sqlitePath;
|
||||
}
|
||||
|
||||
|
@ -7,9 +7,14 @@
|
||||
namespace Older {
|
||||
class Settings {
|
||||
public:
|
||||
Settings();
|
||||
void save();
|
||||
void load();
|
||||
|
||||
uint32_t threads() const;
|
||||
std::string server() const;
|
||||
uint16_t port() const;
|
||||
std::string documentRoot() const;
|
||||
std::string live2dModelsRoot() const;
|
||||
std::string sqlitePath() const;
|
||||
|
||||
@ -18,6 +23,7 @@ private:
|
||||
std::string m_server = "127.0.0.1";
|
||||
uint16_t m_port = 8081;
|
||||
|
||||
std::string m_documentRoot;
|
||||
std::string m_live2dModelsRoot = "resources/live2d";
|
||||
std::string m_sqlitePath = "database.sqlite";
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user