diff --git a/src/mu-msg-iter.cc b/src/mu-msg-iter.cc index f9f1128a..7860c5b9 100644 --- a/src/mu-msg-iter.cc +++ b/src/mu-msg-iter.cc @@ -51,14 +51,14 @@ private: struct _MuMsgIter { - _MuMsgIter (Xapian::Enquire &enq, size_t maxnum): + _MuMsgIter (Xapian::Enquire &enq, size_t maxnum, gboolean threads): _enq(enq), _msg(0), _threadhash (0) { _matches = _enq.get_mset (0, maxnum); - if (!_matches.empty()) { + if (threads && !_matches.empty()) { _matches.fetch(); - _threadhash = mu_msg_threader_calculate (this); + _threadhash = mu_msg_threader_calculate (this, _matches.size()); ThreadKeyMaker keymaker(_threadhash); enq.set_sort_by_key (&keymaker, false); _matches = _enq.get_mset (0, maxnum); @@ -76,7 +76,8 @@ struct _MuMsgIter { if (_msg) mu_msg_unref (_msg); - g_hash_table_destroy (_threadhash); + if (_threadhash) + g_hash_table_destroy (_threadhash); } const Xapian::Enquire _enq; @@ -90,12 +91,12 @@ struct _MuMsgIter { MuMsgIter* -mu_msg_iter_new (XapianEnquire *enq, size_t maxnum) +mu_msg_iter_new (XapianEnquire *enq, size_t maxnum, gboolean threads) { g_return_val_if_fail (enq, NULL); try { - return new MuMsgIter ((Xapian::Enquire&)*enq, maxnum); + return new MuMsgIter ((Xapian::Enquire&)*enq, maxnum, threads); } MU_XAPIAN_CATCH_BLOCK_RETURN(NULL); } diff --git a/src/mu-msg-iter.h b/src/mu-msg-iter.h index 62032d94..6f93b7a1 100644 --- a/src/mu-msg-iter.h +++ b/src/mu-msg-iter.h @@ -44,11 +44,12 @@ typedef struct _MuMsgIter MuMsgIter; * @param enq a Xapian::Enquire* cast to XapianEnquire* (because this * is C, not C++),providing access to search results * @param batchsize how many results to retrieve at once + * @param threads whether to calculate threads * * @return a new MuMsgIter, or NULL in case of error */ MuMsgIter *mu_msg_iter_new (XapianEnquire *enq, - size_t batchsize) G_GNUC_WARN_UNUSED_RESULT; + size_t batchsize, gboolean threads) G_GNUC_WARN_UNUSED_RESULT; /** * get the next message (which you got from @@ -117,7 +118,23 @@ MuMsg* mu_msg_iter_get_msg (MuMsgIter *iter, GError **err) unsigned int mu_msg_iter_get_docid (MuMsgIter *iter); +/** + * calculate the message threads + * + * @param iter a valid MuMsgIter iterator + * + * @return TRUE if it worked, FALSE otherwsie. + */ +gboolean mu_msg_iter_calculate_threads (MuMsgIter *iter); + +/** + * get a sortable string describing the path of a thread + * + * @param iter a valid MuMsgIter iterator + * + * @return a thread path + */ const char* mu_msg_iter_get_thread_path (MuMsgIter *iter); /**