aboutsummaryrefslogtreecommitdiffhomepage
path: root/database.cc
diff options
context:
space:
mode:
authorGravatar Carl Worth <cworth@cworth.org>2009-10-21 23:10:19 -0700
committerGravatar Carl Worth <cworth@cworth.org>2009-10-21 23:21:12 -0700
commitc58ee818b5e116d00172c8406149106c97c2e377 (patch)
treed6c94c7e61a6dd31a38191f61297f5f19d76a352 /database.cc
parent6c5054ebee5beb72c22d91a57c66b8ecdc65f7bf (diff)
Bring back the insert_thread_id function.
We deleted this in favor of our fancy new thread_ids iterator from the message object. But one of the previous callers of insert_thread_id isn't using notmuch_message_t yet. I made the mistake of thinking I could just call g_hash_table_insert directly, but the problem was that nobody was splitting up the thread_id string at its commas. So with this, we were inserting bogus comma-separated IDs into the hash table, so thread_id values were ballooning out of control. Should be much better now.
Diffstat (limited to 'database.cc')
-rw-r--r--database.cc33
1 files changed, 24 insertions, 9 deletions
diff --git a/database.cc b/database.cc
index e46fe5d8..77b2eff2 100644
--- a/database.cc
+++ b/database.cc
@@ -111,6 +111,29 @@ find_message_by_docid (Xapian::Database *db, Xapian::docid docid)
return db->get_document (docid);
}
+static void
+insert_thread_id (GHashTable *thread_ids, Xapian::Document doc)
+{
+ string value_string;
+ const char *value, *id, *comma;
+
+ value_string = doc.get_value (NOTMUCH_VALUE_THREAD);
+ value = value_string.c_str();
+ if (strlen (value)) {
+ id = value;
+ while (*id) {
+ comma = strchr (id, ',');
+ if (comma == NULL)
+ comma = id + strlen (id);
+ g_hash_table_insert (thread_ids,
+ strndup (id, comma - id), NULL);
+ id = comma;
+ if (*id)
+ id++;
+ }
+ }
+}
+
notmuch_message_t *
notmuch_database_find_message (notmuch_database_t *notmuch,
const char *message_id)
@@ -152,16 +175,8 @@ find_thread_ids (notmuch_database_t *notmuch,
find_messages_by_term (db, "ref", message_id, &child, &children_end);
for ( ; child != children_end; child++) {
- const char *thread_id;
doc = find_message_by_docid (db, *child);
-
- thread_id = doc.get_value (NOTMUCH_VALUE_THREAD).c_str ();
- if (strlen (thread_id) == 0) {
- fprintf (stderr, "Database error: Message with doc_id %u has empty thread-id value (value index %d)\n",
- *child, NOTMUCH_VALUE_THREAD);
- } else {
- g_hash_table_insert (thread_ids, strdup (thread_id), NULL);
- }
+ insert_thread_id (thread_ids, doc);
}
for (i = 0; i < parents->len; i++) {