lib: add notmuch_thread_get_total_files

This is relatively inexpensive in terms of run time and implementation
cost as we are already traversing the list of messages in a thread.
This commit is contained in:
David Bremner 2017-06-04 09:32:31 -03:00
parent 8a8e2b11c2
commit 50340bcb78
2 changed files with 21 additions and 0 deletions

View file

@ -1096,6 +1096,18 @@ notmuch_thread_get_thread_id (notmuch_thread_t *thread);
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.

View file

@ -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;
@ -566,6 +569,12 @@ notmuch_thread_get_total_messages (notmuch_thread_t *thread)
return thread->total_messages;
}
int
notmuch_thread_get_total_files (notmuch_thread_t *thread)
{
return thread->total_files;
}
int
notmuch_thread_get_matched_messages (notmuch_thread_t *thread)
{