notmuch_query_search_threads: Avoid returning more threads than asked for.
authorCarl Worth <cworth@cworth.org>
Fri, 13 Nov 2009 04:31:22 +0000 (20:31 -0800)
committerCarl Worth <cworth@cworth.org>
Fri, 13 Nov 2009 04:31:22 +0000 (20:31 -0800)
I thought it would be safe enough to return a few extra threads,
(since we happened to already get the relevant messages out of the
database). The problem is that then requires the caller to carefully
read the number of threads returned and adjust its next "first" value
accordingly. The interface is much simpler to use if we simply return
exactly what is asked for and no more.

lib/query.cc

index 4b4c80f4d5f952d3340ce495c1c2583b984d76ca..381529b538c270695144d4aef8ae7ba673dee996 100644 (file)
@@ -237,6 +237,9 @@ notmuch_query_search_threads (notmuch_query_t *query,
            notmuch_message_destroy (message);
 
            messages_seen++;
+
+           if (max_threads >= 0 && threads_seen >= first + max_threads)
+               break;
        }
 
        /* Stop if we're not seeing any more messages. */