mu4e: use faster count queries, document differences

Use faster queries for counting read/unread messages; document why the
results might differ from what you get doing a normal search.
This commit is contained in:
Dirk-Jan C. Binnema
2020-03-14 14:27:51 +02:00
parent c4953a4310
commit 46ae663937
6 changed files with 42 additions and 50 deletions

View File

@ -1045,16 +1045,17 @@ ping_handler (Context& context, const Parameters& params)
throw Error{Error::Code::Store, &gerr, "failed to read store"};
const auto queries = get_string_vec (params, "queries");
const auto qresults= [&]() -> std::string {
const auto qresults = [&]() -> std::string {
if (queries.empty())
return {};
std::string res{":queries ("};
for (auto&& q: queries) {
const auto count{mu_query_count_run (context.query, q.c_str())};
const auto unreadq{format("(%s) AND flag:unread", q.c_str())};
const auto unreadq{format("flag:unread AND (%s)", q.c_str())};
const auto unread{mu_query_count_run (context.query, unreadq.c_str())};
res += format("(:query %s :count %zu :unread %zu)", quote(q).c_str(), count, unread);
res += format("(:query %s :count %zu :unread %zu)", quote(q).c_str(),
count, unread);
}
return res + ")";
}();
@ -1252,7 +1253,9 @@ make_command_map (Context& context)
cmap.emplace("ping",
CommandInfo{
ArgMap{ {"queries", ArgInfo{Type::List, false,
"queries for which to get read/unread numbers"}}},
"queries for which to get read/unread numbers"}},
{"skip-dups", ArgInfo{Type::Symbol, false,
"whether to exclude messages with duplicate message-ids"}},},
"ping the mu-server and get information in response",
[&](const auto& params){ping_handler(context, params);}});