From 99f473945e95a5cd3bee3009e855c99c4ff63354 Mon Sep 17 00:00:00 2001 From: djcb Date: Thu, 27 Dec 2012 11:07:52 +0200 Subject: [PATCH] * mu-msg-iter: re-introduce MU_MSG_ITER_FLAG_THREADS, and special-case queries with thread support --- lib/mu-msg-iter.cc | 47 +++++++++++++++++++++------------------------- lib/mu-msg-iter.h | 4 +++- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/lib/mu-msg-iter.cc b/lib/mu-msg-iter.cc index c2c1ebda..1caddb87 100644 --- a/lib/mu-msg-iter.cc +++ b/lib/mu-msg-iter.cc @@ -36,9 +36,6 @@ #include "mu-msg-iter.h" #include "mu-threader.h" -/* just a guess... */ -#define MAX_FETCH_SIZE 10000 - class ThreadKeyMaker: public Xapian::KeyMaker { public: ThreadKeyMaker (GHashTable *threadinfo): _threadinfo(threadinfo) {} @@ -57,40 +54,38 @@ struct _MuMsgIter { public: _MuMsgIter (Xapian::Enquire &enq, size_t maxnum, MuMsgFieldId sortfield, MuMsgIterFlags flags): - _enq(enq), _thread_hash (0), _msg(0), _flags(flags) { + _enq(enq), _thread_hash (0), _msg(0), _flags(flags), + _skip_unreadable(flags & MU_MSG_ITER_FLAG_SKIP_UNREADABLE), + _skip_dups (flags & MU_MSG_ITER_FLAG_SKIP_DUPS) { - bool descending; + bool descending = (flags & MU_MSG_ITER_FLAG_DESCENDING); + bool threads = (flags & MU_MSG_ITER_FLAG_THREADS); - descending = (flags & MU_MSG_ITER_FLAG_DESCENDING); - _skip_unreadable = (flags & MU_MSG_ITER_FLAG_SKIP_UNREADABLE); - // set _skip_dups to false, so we'll calculate threadinfo - // for all, and then skip some after sorting - _skip_dups = false; // first, we get _all_ matches (G_MAXINT), based the threads // on that, then return of those _matches = _enq.get_mset (0, G_MAXINT); - _matches.fetch(); - _cursor = _matches.begin(); - if (_matches.empty()) return; - _skip_dups = false; - _thread_hash = mu_threader_calculate - (this, _matches.size(), sortfield, descending); + if (threads) { + _matches.fetch(); + _cursor = _matches.begin(); + _thread_hash = mu_threader_calculate + (this, _matches.size(), sortfield, descending); + + ThreadKeyMaker keymaker(_thread_hash); + enq.set_sort_by_key (&keymaker, false); + _matches = _enq.get_mset (0, maxnum); + + } else if (sortfield != MU_MSG_FIELD_ID_NONE) { + enq.set_sort_by_value ((Xapian::valueno)sortfield, + descending); + _matches = _enq.get_mset (0, maxnum); + _cursor = _matches.begin(); + } - ThreadKeyMaker keymaker(_thread_hash); - enq.set_sort_by_key (&keymaker, false); - _matches = _enq.get_mset (0, maxnum); - _skip_dups = (flags & MU_MSG_ITER_FLAG_SKIP_DUPS); _cursor = _matches.begin(); - - /* this seems to make search slightly faster, some - * non-scientific testing suggests. 5-10% or so */ - if (_matches.size() <= MAX_FETCH_SIZE) - _matches.fetch (); - } ~_MuMsgIter () { diff --git a/lib/mu-msg-iter.h b/lib/mu-msg-iter.h index eb8c2a94..ffd392fd 100644 --- a/lib/mu-msg-iter.h +++ b/lib/mu-msg-iter.h @@ -45,7 +45,9 @@ enum _MuMsgIterFlags { * readable message-file? */ MU_MSG_ITER_FLAG_SKIP_UNREADABLE = 1 << 1, /* ignore duplicate messages? */ - MU_MSG_ITER_FLAG_SKIP_DUPS = 1 << 2 + MU_MSG_ITER_FLAG_SKIP_DUPS = 1 << 2, + /* calculate threads? */ + MU_MSG_ITER_FLAG_THREADS = 1 << 3 }; typedef unsigned MuMsgIterFlags;