From 6f0b50218b33bca8f5a607714843879aeff7a532 Mon Sep 17 00:00:00 2001 From: luocai Date: Wed, 7 Aug 2024 15:47:30 +0800 Subject: [PATCH] add size filter. --- Server/Database/Database.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Server/Database/Database.cpp b/Server/Database/Database.cpp index 5c1fc93..136e3dc 100644 --- a/Server/Database/Database.cpp +++ b/Server/Database/Database.cpp @@ -213,14 +213,15 @@ std::list Database::mostViewedUrls(int size) { pv.url = reinterpret_cast(sqlite3_column_text(stmt, 0)); if (std::find(urlFilter.cbegin(), urlFilter.cend(), pv.url) != urlFilter.cend()) continue; pv.pageViewCount = sqlite3_column_int(stmt, 1); - ret.push_back(pv); + if (ret.size() < size) { + ret.push_back(pv); + } } if (rc != SQLITE_DONE) { LOG(error) << "Failed to execute statement: " << sqlite3_errmsg(m_sqlite3); } sqlite3_finalize(stmt); - return ret; } @@ -251,7 +252,9 @@ std::list Database::latestViewedUrls(int size) { visit.url = reinterpret_cast(sqlite3_column_text(stmt, 0)); if (std::find(urlFilter.cbegin(), urlFilter.cend(), visit.url) != urlFilter.cend()) continue; visit.lastViewTime = sqlite3_column_int64(stmt, 1); - ret.push_back(visit); + if (ret.size() < size) { + ret.push_back(visit); + } } return ret; }