summaryrefslogtreecommitdiff
path: root/src/database
diff options
context:
space:
mode:
Diffstat (limited to 'src/database')
-rw-r--r--src/database/database.cpp26
-rw-r--r--src/database/database.hpp4
2 files changed, 19 insertions, 11 deletions
diff --git a/src/database/database.cpp b/src/database/database.cpp
index 3b3e890..6e08ee1 100644
--- a/src/database/database.cpp
+++ b/src/database/database.cpp
@@ -190,12 +190,9 @@ std::string Database::store_muc_message(const std::string& owner, const std::str
return uuid;
}
-std::vector<Database::MucLogLine> Database::get_muc_logs(const std::string& owner, const std::string& chan_name, const std::string& server,
- int limit, const std::string& start, const std::string& end, const Id::real_type reference_record_id, Database::Paging paging)
+std::tuple<bool, std::vector<Database::MucLogLine>> Database::get_muc_logs(const std::string& owner, const std::string& chan_name, const std::string& server,
+ std::size_t limit, const std::string& start, const std::string& end, const Id::real_type reference_record_id, Database::Paging paging)
{
- if (limit == 0)
- return {};
-
auto request = select(Database::muc_log_lines);
request.where() << Database::Owner{} << "=" << owner << \
" and " << Database::IrcChanName{} << "=" << chan_name << \
@@ -228,15 +225,26 @@ std::vector<Database::MucLogLine> Database::get_muc_logs(const std::string& owne
else
request.order_by() << Id{} << " DESC ";
- if (limit >= 0)
- request.limit() << limit;
+ // Just a simple trick: to know whether we got the totality of the
+ // possible results matching this query (except for the limit), we just
+ // ask one more element. If we get that additional element, this means
+ // we don’t have everything. And then we just discard it. If we don’t
+ // have more, this means we have everything.
+ request.limit() << limit + 1;
auto result = request.execute(*Database::db);
+ bool complete = true;
+
+ if (result.size() == limit + 1)
+ {
+ complete = false;
+ result.erase(std::prev(result.end()));
+ }
if (paging == Database::Paging::first)
- return result;
+ return {complete, result};
else
- return {result.crbegin(), result.crend()};
+ return {complete, {result.crbegin(), result.crend()}};
}
Database::MucLogLine Database::get_muc_log(const std::string& owner, const std::string& chan_name, const std::string& server,
diff --git a/src/database/database.hpp b/src/database/database.hpp
index 30ffcb4..3e25b30 100644
--- a/src/database/database.hpp
+++ b/src/database/database.hpp
@@ -131,8 +131,8 @@ class Database
* Get all the lines between (optional) start and end dates, with a (optional) limit.
* If after_id is set, only the records after it will be returned.
*/
- static std::vector<MucLogLine> get_muc_logs(const std::string& owner, const std::string& chan_name, const std::string& server,
- int limit=-1, const std::string& start="", const std::string& end="",
+ static std::tuple<bool, std::vector<MucLogLine>> get_muc_logs(const std::string& owner, const std::string& chan_name, const std::string& server,
+ std::size_t limit, const std::string& start="", const std::string& end="",
const Id::real_type reference_record_id=Id::unset_value, Paging=Paging::first);
/**