From 684e794f0be461eab0804edd42d096597fe429f9 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Sat, 4 Oct 2014 10:19:09 +2000 Subject: [PATCH] [PATCH 02/11] lib: Refactor _notmuch_database_link_message --- 09/58402769ce603e0f27f0fff2e8c23012d1b93e | 193 ++++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 09/58402769ce603e0f27f0fff2e8c23012d1b93e diff --git a/09/58402769ce603e0f27f0fff2e8c23012d1b93e b/09/58402769ce603e0f27f0fff2e8c23012d1b93e new file mode 100644 index 000000000..fdcb7ddac --- /dev/null +++ b/09/58402769ce603e0f27f0fff2e8c23012d1b93e @@ -0,0 +1,193 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 1CF58431FC9 + for ; Fri, 3 Oct 2014 07:19:51 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -2.3 +X-Spam-Level: +X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id 4BS46qkmBdwK for ; + Fri, 3 Oct 2014 07:19:45 -0700 (PDT) +Received: from dmz-mailsec-scanner-3.mit.edu (dmz-mailsec-scanner-3.mit.edu + [18.9.25.14]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id A4DFF431FD4 + for ; Fri, 3 Oct 2014 07:19:26 -0700 (PDT) +X-AuditID: 1209190e-f79d46d000003643-1c-542eb06db730 +Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) + (using TLS with cipher AES256-SHA (256/256 bits)) + (Client did not present a certificate) + by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP + id 11.C6.13891.D60BE245; Fri, 3 Oct 2014 10:19:25 -0400 (EDT) +Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) + by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id s93EJOum021145; + Fri, 3 Oct 2014 10:19:24 -0400 +Received: from drake.dyndns.org + (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com + [216.15.114.40]) (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s93EJLOT023308 + (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); + Fri, 3 Oct 2014 10:19:24 -0400 +Received: from amthrax by drake.dyndns.org with local (Exim 4.84) + (envelope-from ) + id 1Xa3hZ-0002Jc-0V; Fri, 03 Oct 2014 10:19:21 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH 02/11] lib: Refactor _notmuch_database_link_message +Date: Fri, 3 Oct 2014 10:19:09 -0400 +Message-Id: <1412345958-8278-3-git-send-email-aclements@csail.mit.edu> +X-Mailer: git-send-email 2.1.0 +In-Reply-To: <1412345958-8278-1-git-send-email-aclements@csail.mit.edu> +References: <1412345958-8278-1-git-send-email-aclements@csail.mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFtrAIsWRmVeSWpSXmKPExsUixG6nopu7QS/E4MIxC4vrN2cyOzB6PFt1 + izmAMYrLJiU1J7MstUjfLoEr48JShYJmuYpl8zezNzBuFu9i5OSQEDCRODxpBzuELSZx4d56 + ti5GLg4hgdlMEpNuHYByNjBKHPmxiR3Cuc0kcWXBHlaQFiGBJYwS0ydpgdhsAvoSK9ZOAouL + CEhL7Lw7G8jm4GAWUJP406UCYgoLOEt836ECUsEioCqxdOsqsMW8Am4SK548YoY4Qk5iw+7/ + jCA2p4C7xIW7T9kgNrlJrDrWzTaBkX8BI8MqRtmU3Crd3MTMnOLUZN3i5MS8vNQiXWO93MwS + vdSU0k2MoIDhlOTbwfj1oNIhRgEORiUe3g83dEOEWBPLiitzDzFKcjApifJWLtYLEeJLyk+p + zEgszogvKs1JLT7EKMHBrCTCu2AlUI43JbGyKrUoHyYlzcGiJM676QdfiJBAemJJanZqakFq + EUxWhoNDSYK3fT1Qo2BRanpqRVpmTglCmomDE2Q4D9BwsBre4oLE3OLMdIj8KUZFKXHeh+uA + EgIgiYzSPLheWES/YhQHekWYtwuknQeYDOC6XwENZgIa/M5eF2RwSSJCSqqBccHSqXas/0V8 + WB0C7DjjdnoxB7t7/tzwKfH7tAWvDQ09NBZIz/OoE97CE7ivNzmzsuXiyV81j9Y3fQ9JvLQh + Ln3V4rtMN5e9/ZPRxGqsIaqxZPati6kBm5j2vFS4+2RRC4+0aMqh0/7/SnLC1fTX8G03cBIy + ZRTq4Xyhcs7igMDjKYJinZf6lViKMxINtZiLihMBKo+WW8MCAAA= +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Fri, 03 Oct 2014 14:19:51 -0000 + +From: Austin Clements + +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 (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 (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 + -- 2.26.2