From e456998e7de56752de74b7484d9f92d80b138f8e Mon Sep 17 00:00:00 2001 From: djcb Date: Wed, 26 Dec 2012 10:12:25 +0200 Subject: [PATCH] * mu-query: create the query in a smarter way, which makes --include-related *much* faster --- lib/mu-query.cc | 18 +++++++----------- man/mu-find.1 | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/lib/mu-query.cc b/lib/mu-query.cc index 4fb781e8..d82eced0 100644 --- a/lib/mu-query.cc +++ b/lib/mu-query.cc @@ -422,7 +422,7 @@ get_related_query (MuMsgIter *iter) { GHashTable *hash; GList *id_list, *cur; - Xapian::Query query; + std::vector qvec; static std::string pfx (1, mu_msg_field_xapian_prefix (MU_MSG_FIELD_ID_THREAD_ID)); @@ -432,20 +432,16 @@ get_related_query (MuMsgIter *iter) * References. */ id_list = g_hash_table_get_keys (hash); - /* now, let's create a new query matching all of those */ - // g_print ("list: %u\n", (unsigned) g_list_length (id_list)); - for (cur = id_list; cur; cur = g_list_next(cur)) { - query = Xapian::Query (Xapian::Query::OP_OR, - query, - Xapian::Query((std::string - (pfx + (char*)cur->data)))); - } + // now, we create a vector with queries for each of the + // thread-ids, which we combine below. This is /much/ faster + // than creating the query as 'query = Query (OR, query)'... + for (cur = id_list; cur; cur = g_list_next(cur)) + qvec.push_back (Xapian::Query((std::string (pfx + (char*)cur->data)))); g_hash_table_destroy (hash); g_list_free (id_list); - /* now, `query' should match all related messages */ - return query; + return Xapian::Query (Xapian::Query::OP_OR, qvec.begin(), qvec.end()); } diff --git a/man/mu-find.1 b/man/mu-find.1 index d611ed73..092fe955 100644 --- a/man/mu-find.1 +++ b/man/mu-find.1 @@ -439,7 +439,7 @@ same message, which is a common occurence when using e.g. Gmail together with the matched messages -- i.e.. include messages that are part of the same message thread as some matched messages. This is useful if you want Gmail-style 'conversations'. Note, finding these related messages can take a -bit of time if there are more than a thousand matches. +bit of time if there are thousands of matches. .TP \fB\-t\fR, \fB\-\-threads\fR show messages in a 'threaded' format -- that is,