mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-25 12:28:09 +01:00
notmuch search: Avoid printing duplicate author names.
We add a hash to the thread object so that we can detect author names that have already been added to the list, and avoid adding them redundantly. This avoids the giant chain of "bugzilla-daemon, bugzilla-daemon, bugzilla-daemon, bugzilla-daemon, ..." author lists that we would get otherwise, for example.
This commit is contained in:
parent
ec6d3506db
commit
c3c0966521
1 changed files with 26 additions and 8 deletions
|
@ -30,6 +30,7 @@ struct _notmuch_thread {
|
||||||
notmuch_database_t *notmuch;
|
notmuch_database_t *notmuch;
|
||||||
char *thread_id;
|
char *thread_id;
|
||||||
char *subject;
|
char *subject;
|
||||||
|
GHashTable *authors_hash;
|
||||||
char *authors;
|
char *authors;
|
||||||
GHashTable *tags;
|
GHashTable *tags;
|
||||||
|
|
||||||
|
@ -41,11 +42,33 @@ struct _notmuch_thread {
|
||||||
static int
|
static int
|
||||||
_notmuch_thread_destructor (notmuch_thread_t *thread)
|
_notmuch_thread_destructor (notmuch_thread_t *thread)
|
||||||
{
|
{
|
||||||
|
g_hash_table_unref (thread->authors_hash);
|
||||||
g_hash_table_unref (thread->tags);
|
g_hash_table_unref (thread->tags);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_thread_add_author (notmuch_thread_t *thread,
|
||||||
|
const char *author)
|
||||||
|
{
|
||||||
|
if (author == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (g_hash_table_lookup_extended (thread->authors_hash,
|
||||||
|
author, NULL, NULL))
|
||||||
|
return;
|
||||||
|
|
||||||
|
g_hash_table_insert (thread->authors_hash, xstrdup (author), NULL);
|
||||||
|
|
||||||
|
if (thread->authors)
|
||||||
|
thread->authors = talloc_asprintf (thread, "%s, %s",
|
||||||
|
thread->authors,
|
||||||
|
author);
|
||||||
|
else
|
||||||
|
thread->authors = talloc_strdup (thread, author);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
_thread_add_message (notmuch_thread_t *thread,
|
_thread_add_message (notmuch_thread_t *thread,
|
||||||
notmuch_message_t *message)
|
notmuch_message_t *message)
|
||||||
|
@ -68,14 +91,7 @@ _thread_add_message (notmuch_thread_t *thread,
|
||||||
mailbox = INTERNET_ADDRESS_MAILBOX (address);
|
mailbox = INTERNET_ADDRESS_MAILBOX (address);
|
||||||
author = internet_address_mailbox_get_addr (mailbox);
|
author = internet_address_mailbox_get_addr (mailbox);
|
||||||
}
|
}
|
||||||
if (author) {
|
_thread_add_author (thread, author);
|
||||||
if (thread->authors)
|
|
||||||
thread->authors = talloc_asprintf (thread, "%s, %s",
|
|
||||||
thread->authors,
|
|
||||||
author);
|
|
||||||
else
|
|
||||||
thread->authors = talloc_strdup (thread, author);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
g_object_unref (G_OBJECT (list));
|
g_object_unref (G_OBJECT (list));
|
||||||
}
|
}
|
||||||
|
@ -150,6 +166,8 @@ _notmuch_thread_create (const void *ctx,
|
||||||
thread->notmuch = notmuch;
|
thread->notmuch = notmuch;
|
||||||
thread->thread_id = talloc_strdup (thread, thread_id);
|
thread->thread_id = talloc_strdup (thread, thread_id);
|
||||||
thread->subject = NULL;
|
thread->subject = NULL;
|
||||||
|
thread->authors_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||||
|
free, NULL);
|
||||||
thread->authors = NULL;
|
thread->authors = NULL;
|
||||||
thread->tags = g_hash_table_new_full (g_str_hash, g_str_equal,
|
thread->tags = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||||
free, NULL);
|
free, NULL);
|
||||||
|
|
Loading…
Reference in a new issue