]> git.notmuchmail.org Git - notmuch/blobdiff - lib/query.cc
notmuch_query_search_threads: Avoid returning more threads than asked for.
[notmuch] / lib / query.cc
index 2169709c7ddcb57980691287670e9cb038c7d151..381529b538c270695144d4aef8ae7ba673dee996 100644 (file)
@@ -218,7 +218,7 @@ notmuch_query_search_threads (notmuch_query_t *query,
                                                thread_id, NULL,
                                                (void **) &thread))
            {
-               if (threads_seen > first) {
+               if (threads_seen >= first) {
                    thread = _notmuch_thread_create (query, query->notmuch,
                                                     thread_id);
                    g_ptr_array_add (threads->threads, thread);
@@ -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. */