unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Bremner <david@tethera.net>
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	[thread overview]
Message-ID: <20170721105840.4737-9-david@tethera.net> (raw)
In-Reply-To: <20170721105840.4737-1-david@tethera.net>

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

  parent reply	other threads:[~2017-07-21 10:59 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-21 10:58 v4 of index multiple files per msg-id, add reindex command David Bremner
2017-07-21 10:58 ` [Patch v4 01/12] lib: isolate n_d_add_message and helper functions into own file David Bremner
2017-07-21 10:58 ` [Patch v4 02/12] lib/n_d_add_message: refactor test for new/ghost messages David Bremner
2017-07-21 10:58 ` [Patch v4 03/12] lib: factor out message-id parsing to separate file David Bremner
2017-07-21 10:58 ` [Patch v4 04/12] lib: refactor notmuch_database_add_message header parsing David Bremner
2017-07-21 10:58 ` [Patch v4 05/12] test: add known broken tests for duplicate message id David Bremner
2017-07-21 10:58 ` [Patch v4 06/12] lib: index message files with duplicate message-ids David Bremner
2017-07-21 10:58 ` [Patch v4 07/12] lib: add notmuch_message_count_files David Bremner
2017-07-21 10:58 ` David Bremner [this message]
2017-07-21 10:58 ` [Patch v4 09/12] cli/search: print total number of files matched in summary output David Bremner
2017-07-21 10:58 ` [Patch v4 10/12] lib: add _notmuch_message_remove_indexed_terms David Bremner
2017-07-21 10:58 ` [Patch v4 11/12] lib: add notmuch_message_reindex David Bremner
2017-07-21 10:58 ` [Patch v4 12/12] add "notmuch reindex" subcommand David Bremner
2017-08-02  2:53 ` v4 of index multiple files per msg-id, add reindex command David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170721105840.4737-9-david@tethera.net \
    --to=david@tethera.net \
    --cc=notmuch@freelists.org \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).