This commit is contained in:
parent
a6553d3597
commit
6c5b2d92ac
@ -15,6 +15,16 @@
|
||||
|
||||
constexpr auto IpcUrl = "ipc:///tmp/nng_ipc_server";
|
||||
|
||||
static std::vector<std::string> urlFilter = {
|
||||
"/",
|
||||
"/search",
|
||||
"/LoginPage",
|
||||
"/MessageBoard",
|
||||
"/我的笔记",
|
||||
"/我的笔记/",
|
||||
"/我的博客",
|
||||
};
|
||||
|
||||
Application::Application(const std::string &path)
|
||||
: ApplicationSettings(path), m_router{std::make_shared<boost::urls::router<RequestHandler>>()} {
|
||||
|
||||
@ -149,7 +159,8 @@ Application::Application(const std::string &path)
|
||||
url = root["url"].as_string();
|
||||
}
|
||||
auto database = Database::session();
|
||||
if (std::filesystem::exists("amass_blog" + url) && url.find("/我的博客/page") != 0) {
|
||||
// if (std::filesystem::exists("amass_blog" + url) && url.find("/我的博客/page") != 0) {
|
||||
{
|
||||
Wt::Dbo::Transaction transaction(*database);
|
||||
auto record = std::make_unique<VisitorRecord>();
|
||||
record->time = std::chrono::system_clock::now();
|
||||
@ -196,13 +207,17 @@ Application::Application(const std::string &path)
|
||||
}
|
||||
auto database = Database::session();
|
||||
Wt::Dbo::Transaction transaction(*database);
|
||||
Wt::Dbo::collection<std::tuple<std::string, int>> query = database->query<std::tuple<std::string, int>>("SELECT url, COUNT(*) as count FROM visitor_record GROUP BY url ORDER BY count DESC LIMIT ?").bind(size);
|
||||
Wt::Dbo::collection<std::tuple<std::string, int>> query = database->query<std::tuple<std::string, int>>("SELECT url, COUNT(*) as count FROM visitor_record GROUP BY url ORDER BY count DESC LIMIT ?").bind(static_cast<int> (size+urlFilter.size()));
|
||||
boost::json::array reply;
|
||||
int index = 0;
|
||||
for (auto &[url, count] : query) {
|
||||
if (std::find(urlFilter.cbegin(), urlFilter.cend(),url) != urlFilter.cend()) continue;
|
||||
boost::json::object object;
|
||||
object["url"] = url;
|
||||
object["count"] = count;
|
||||
reply.push_back(std::move(object));
|
||||
index++;
|
||||
if(index>=size)break;
|
||||
}
|
||||
http::response<boost::beast::http::string_body> s{boost::beast::http::status::ok, request.version()};
|
||||
s.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
@ -232,13 +247,17 @@ Application::Application(const std::string &path)
|
||||
auto database = Database::session();
|
||||
Wt::Dbo::Transaction transaction(*database);
|
||||
using Reslut = std::tuple<std::string, system_clock::time_point>;
|
||||
Wt::Dbo::collection<Reslut> query = database->query<Reslut>("SELECT url, MAX(time) FROM visitor_record GROUP BY url ORDER BY MAX(time) DESC LIMIT ?").bind(size);
|
||||
Wt::Dbo::collection<Reslut> query = database->query<Reslut>("SELECT url, MAX(time) FROM visitor_record GROUP BY url ORDER BY MAX(time) DESC LIMIT ?").bind(static_cast<int> (size+urlFilter.size()));
|
||||
boost::json::array reply;
|
||||
int index=0;
|
||||
for (auto &[url, time] : query) {
|
||||
if (std::find(urlFilter.cbegin(), urlFilter.cend(),url) != urlFilter.cend()) continue;
|
||||
boost::json::object object;
|
||||
object["url"] = url;
|
||||
object["time"] = duration_cast<seconds>(time.time_since_epoch()).count();
|
||||
reply.push_back(std::move(object));
|
||||
index++;
|
||||
if(index>=size)break;
|
||||
}
|
||||
http::response<boost::beast::http::string_body> s{boost::beast::http::status::ok, request.version()};
|
||||
s.set(http::field::server, BOOST_BEAST_VERSION_STRING);
|
||||
|
Loading…
Reference in New Issue
Block a user