mu-query: small optimization tweaks

This commit is contained in:
Dirk-Jan C. Binnema
2023-08-01 22:48:03 +03:00
parent aea95b5be0
commit 25151aad00

View File

@ -1,5 +1,5 @@
/* /*
** Copyright (C) 2008-2021 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> ** Copyright (C) 2008-2023 Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
** **
** This program is free software; you can redistribute it and/or modify ** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by ** it under the terms of the GNU General Public License as published by
@ -93,7 +93,6 @@ Query::Private::make_enquire(const std::string& expr,
for (auto&& w : warns) for (auto&& w : warns)
mu_warning("query warning: {}", to_string(w)); mu_warning("query warning: {}", to_string(w));
enq.set_query(xapian_query(tree)); enq.set_query(xapian_query(tree));
mu_debug("qtree: {}", to_string(tree));
} }
sort_enquire(enq, sortfield_id, qflags); sort_enquire(enq, sortfield_id, qflags);
@ -108,6 +107,8 @@ Query::Private::make_related_enquire(const StringSet& thread_ids,
{ {
auto enq{store_.xapian_db().enquire()}; auto enq{store_.xapian_db().enquire()};
std::vector<Xapian::Query> qvec; std::vector<Xapian::Query> qvec;
qvec.reserve(thread_ids.size());
for (auto&& t : thread_ids) for (auto&& t : thread_ids)
qvec.emplace_back(field_from_id(Field::Id::ThreadId).xapian_term(t)); qvec.emplace_back(field_from_id(Field::Id::ThreadId).xapian_term(t));
@ -212,11 +213,10 @@ Query::Private::run_related(const std::string& expr,
// Gather the thread-ids we found // Gather the thread-ids we found
mset.fetch(); mset.fetch();
for (auto it = mset.begin(); it != mset.end(); ++it) { minfo.thread_ids.reserve(mset.size());
auto thread_id{opt_string(it.get_document(), Field::Id::ThreadId)}; for (auto it = mset.begin(); it != mset.end(); ++it)
if (thread_id) if (auto thread_id{opt_string(it.get_document(), Field::Id::ThreadId)}; thread_id)
minfo.thread_ids.emplace(std::move(*thread_id)); minfo.thread_ids.emplace(std::move(*thread_id));
}
// Now, determine the "related query". // Now, determine the "related query".
// //
@ -226,7 +226,7 @@ Query::Private::run_related(const std::string& expr,
auto r_enq = std::invoke([&]{ auto r_enq = std::invoke([&]{
if (threading) if (threading)
return make_related_enquire(minfo.thread_ids, Field::Id::Date, return make_related_enquire(minfo.thread_ids, Field::Id::Date,
qflags ); qflags);
else else
return make_related_enquire(minfo.thread_ids, sortfield_id, qflags); return make_related_enquire(minfo.thread_ids, sortfield_id, qflags);
}); });