From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 92EBE6DE0BBB for ; Fri, 21 Jul 2017 03:59:20 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.849 X-Spam-Level: X-Spam-Status: No, score=0.849 tagged_above=-999 required=5 tests=[AWL=-0.840, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01, URIBL_BLACK=1.7] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id A4QG2SRioncy for ; Fri, 21 Jul 2017 03:59:20 -0700 (PDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id B78686DE02DD for ; Fri, 21 Jul 2017 03:59:00 -0700 (PDT) Received: from remotemail by fethera.tethera.net with local (Exim 4.84_2) (envelope-from ) id 1dYVat-00030G-0z; Fri, 21 Jul 2017 06:55:39 -0400 Received: (nullmailer pid 4912 invoked by uid 1000); Fri, 21 Jul 2017 10:58:47 -0000 From: David Bremner To: notmuch@notmuchmail.org, notmuch@freelists.org Subject: [Patch v4 08/12] lib: add notmuch_thread_get_total_files Date: Fri, 21 Jul 2017 07:58:36 -0300 Message-Id: <20170721105840.4737-9-david@tethera.net> X-Mailer: git-send-email 2.13.2 In-Reply-To: <20170721105840.4737-1-david@tethera.net> References: <20170721105840.4737-1-david@tethera.net> X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Jul 2017 10:59:20 -0000 This is relatively inexpensive in terms of run time and implementation cost as we are already traversing the list of messages in a thread. --- lib/notmuch.h | 12 ++++++++++++ lib/thread.cc | 9 +++++++++ 2 files changed, 21 insertions(+) diff --git a/lib/notmuch.h b/lib/notmuch.h index f5018497..4c03a893 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -1097,6 +1097,18 @@ int notmuch_thread_get_total_messages (notmuch_thread_t *thread); /** + * Get the total number of files in 'thread'. + * + * This sums notmuch_message_count_files over all messages in the + * thread + * @returns Non-negative integer + * @since libnotmuch 5.0 (notmuch 0.25) + */ + +int +notmuch_thread_get_total_files (notmuch_thread_t *thread); + +/** * Get a notmuch_messages_t iterator for the top-level messages in * 'thread' in oldest-first order. * diff --git a/lib/thread.cc b/lib/thread.cc index 1a1ecfa5..e17ef63e 100644 --- a/lib/thread.cc +++ b/lib/thread.cc @@ -44,6 +44,7 @@ struct _notmuch_thread { GHashTable *message_hash; int total_messages; + int total_files; int matched_messages; time_t oldest; time_t newest; @@ -266,6 +267,7 @@ _thread_add_message (notmuch_thread_t *thread, _notmuch_message_list_add_message (thread->message_list, talloc_steal (thread, message)); thread->total_messages++; + thread->total_files += notmuch_message_count_files (message); g_hash_table_insert (thread->message_hash, xstrdup (notmuch_message_get_message_id (message)), @@ -495,6 +497,7 @@ _notmuch_thread_create (void *ctx, free, NULL); thread->total_messages = 0; + thread->total_files = 0; thread->matched_messages = 0; thread->oldest = 0; thread->newest = 0; @@ -567,6 +570,12 @@ notmuch_thread_get_total_messages (notmuch_thread_t *thread) } int +notmuch_thread_get_total_files (notmuch_thread_t *thread) +{ + return thread->total_files; +} + +int notmuch_thread_get_matched_messages (notmuch_thread_t *thread) { return thread->matched_messages; -- 2.13.2