From: Austin Clements <aclements@csail.mit.edu>
To: notmuch@notmuchmail.org
Subject: [PATCH 02/11] lib: Refactor _notmuch_database_link_message
Date: Fri, 3 Oct 2014 10:19:09 -0400 [thread overview]
Message-ID: <1412345958-8278-3-git-send-email-aclements@csail.mit.edu> (raw)
In-Reply-To: <1412345958-8278-1-git-send-email-aclements@csail.mit.edu>
From: Austin Clements <amdragon@mit.edu>
This moves the code to retrieve and clear the metadata thread ID out
of _notmuch_database_link_message into its own function. This will
simplify future changes.
---
lib/database.cc | 69 +++++++++++++++++++++++++++++++++++----------------------
1 file changed, 43 insertions(+), 26 deletions(-)
diff --git a/lib/database.cc b/lib/database.cc
index 4e68706..1c6ffc5 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -1958,6 +1958,37 @@ _notmuch_database_link_message_to_children (notmuch_database_t *notmuch,
return ret;
}
+/* Fetch and clear the stored thread_id for message, or NULL if none. */
+static char *
+_consume_metadata_thread_id (void *ctx, notmuch_database_t *notmuch,
+ notmuch_message_t *message)
+{
+ const char *message_id;
+ string stored_id;
+ char *metadata_key;
+
+ message_id = notmuch_message_get_message_id (message);
+ metadata_key = _get_metadata_thread_id_key (ctx, message_id);
+
+ /* Check if we have already seen related messages to this one.
+ * If we have then use the thread_id that we stored at that time.
+ */
+ stored_id = notmuch->xapian_db->get_metadata (metadata_key);
+ if (stored_id.empty ()) {
+ return NULL;
+ } else {
+ Xapian::WritableDatabase *db;
+
+ db = static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db);
+
+ /* Clear the metadata for this message ID. We don't need it
+ * anymore. */
+ db->set_metadata (metadata_key, "");
+
+ return talloc_strdup (ctx, stored_id.c_str ());
+ }
+}
+
/* Given a (mostly empty) 'message' and its corresponding
* 'message_file' link it to existing threads in the database.
*
@@ -1988,42 +2019,25 @@ _notmuch_database_link_message (notmuch_database_t *notmuch,
notmuch_message_t *message,
notmuch_message_file_t *message_file)
{
+ void *local = talloc_new (NULL);
notmuch_status_t status;
- const char *message_id, *thread_id = NULL;
- char *metadata_key;
- string stored_id;
-
- message_id = notmuch_message_get_message_id (message);
- metadata_key = _get_metadata_thread_id_key (message, message_id);
-
- /* Check if we have already seen related messages to this one.
- * If we have then use the thread_id that we stored at that time.
- */
- stored_id = notmuch->xapian_db->get_metadata (metadata_key);
- if (! stored_id.empty()) {
- Xapian::WritableDatabase *db;
-
- db = static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db);
-
- /* Clear the metadata for this message ID. We don't need it
- * anymore. */
- db->set_metadata (metadata_key, "");
- thread_id = stored_id.c_str();
+ const char *thread_id;
- _notmuch_message_add_term (message, "thread", thread_id);
- }
- talloc_free (metadata_key);
+ /* Check if the message already had a thread ID */
+ thread_id = _consume_metadata_thread_id (local, notmuch, message);
+ if (thread_id)
+ _notmuch_message_add_term (message, "thread", thread_id);
status = _notmuch_database_link_message_to_parents (notmuch, message,
message_file,
&thread_id);
if (status)
- return status;
+ goto DONE;
status = _notmuch_database_link_message_to_children (notmuch, message,
&thread_id);
if (status)
- return status;
+ goto DONE;
/* If not part of any existing thread, generate a new thread ID. */
if (thread_id == NULL) {
@@ -2032,7 +2046,10 @@ _notmuch_database_link_message (notmuch_database_t *notmuch,
_notmuch_message_add_term (message, "thread", thread_id);
}
- return NOTMUCH_STATUS_SUCCESS;
+ DONE:
+ talloc_free (local);
+
+ return status;
}
notmuch_status_t
--
2.1.0
next prev parent reply other threads:[~2014-10-03 14:19 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-03 14:19 [PATCH 00/11] Add ghost messages and fix thread linking Austin Clements
2014-10-03 14:19 ` [PATCH 01/11] lib: Move message ID compression to _notmuch_message_create_for_message_id Austin Clements
2014-10-03 14:19 ` Austin Clements [this message]
2014-10-05 7:45 ` [PATCH 02/11] lib: Refactor _notmuch_database_link_message David Bremner
2014-10-05 23:20 ` Austin Clements
2014-10-06 6:04 ` David Bremner
2014-10-06 13:25 ` Austin Clements
2014-10-03 14:19 ` [PATCH 03/11] lib: Handle empty date value Austin Clements
2014-10-03 14:19 ` [PATCH 04/11] lib: Add a ghost messages database feature Austin Clements
2014-10-03 14:19 ` [PATCH 05/11] lib: Update database schema doc for ghost messages Austin Clements
2014-10-03 14:19 ` [PATCH 06/11] lib: Internal support for querying and creating " Austin Clements
2014-10-05 8:30 ` David Bremner
2014-10-05 23:24 ` Austin Clements
2014-10-06 6:19 ` David Bremner
2014-10-06 16:03 ` Austin Clements
2014-10-03 14:19 ` [PATCH 07/11] lib: Implement ghost-based thread linking Austin Clements
2014-10-03 14:19 ` [PATCH 08/11] lib: Implement upgrade to ghost messages feature Austin Clements
2014-10-05 8:56 ` David Bremner
2014-10-05 23:29 ` Austin Clements
2014-10-06 6:03 ` David Bremner
2014-10-03 14:19 ` [PATCH 09/11] lib: Enable " Austin Clements
2014-10-03 14:19 ` [PATCH 10/11] test: Test upgrade to " Austin Clements
2014-10-03 14:19 ` [PATCH 11/11] lib: Remove unnecessary thread linking steps when using ghost messages Austin Clements
2014-10-04 8:30 ` [PATCH 00/11] Add ghost messages and fix thread linking Tomi Ollila
2014-10-04 20:15 ` Austin Clements
2014-10-05 9:07 ` 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=1412345958-8278-3-git-send-email-aclements@csail.mit.edu \
--to=aclements@csail.mit.edu \
--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).