1 Return-Path: <aclements@csail.mit.edu>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 16CEF431FAF
\r
6 for <notmuch@notmuchmail.org>; Mon, 6 Oct 2014 16:17:39 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id 94FECnKpB2Wf for <notmuch@notmuchmail.org>;
\r
16 Mon, 6 Oct 2014 16:17:34 -0700 (PDT)
\r
17 Received: from dmz-mailsec-scanner-5.mit.edu (dmz-mailsec-scanner-5.mit.edu
\r
19 by olra.theworths.org (Postfix) with ESMTP id 43228431FAE
\r
20 for <notmuch@notmuchmail.org>; Mon, 6 Oct 2014 16:17:30 -0700 (PDT)
\r
21 X-AuditID: 12074422-f79436d000000c21-0f-54332309846b
\r
22 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])
\r
23 (using TLS with cipher AES256-SHA (256/256 bits))
\r
24 (Client did not present a certificate)
\r
25 by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP
\r
26 id 62.37.03105.90323345; Mon, 6 Oct 2014 19:17:29 -0400 (EDT)
\r
27 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])
\r
28 by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id s96NHP4J025204;
\r
29 Mon, 6 Oct 2014 19:17:25 -0400
\r
30 Received: from drake.dyndns.org ([12.185.136.2]) (authenticated bits=0)
\r
31 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
32 by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s96NHMOI014461
\r
33 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT);
\r
34 Mon, 6 Oct 2014 19:17:24 -0400
\r
35 Received: from amthrax by drake.dyndns.org with local (Exim 4.84)
\r
36 (envelope-from <aclements@csail.mit.edu>)
\r
37 id 1XbHWr-0001JL-LH; Mon, 06 Oct 2014 17:17:21 -0600
\r
38 From: Austin Clements <aclements@csail.mit.edu>
\r
39 To: notmuch@notmuchmail.org
\r
40 Subject: [PATCH v2 02/12] lib: Refactor _notmuch_database_link_message
\r
41 Date: Mon, 6 Oct 2014 17:17:08 -0600
\r
42 Message-Id: <1412637438-4821-3-git-send-email-aclements@csail.mit.edu>
\r
43 X-Mailer: git-send-email 2.1.0
\r
44 In-Reply-To: <1412637438-4821-1-git-send-email-aclements@csail.mit.edu>
\r
45 References: <1412637438-4821-1-git-send-email-aclements@csail.mit.edu>
\r
46 X-Brightmail-Tracker:
\r
47 H4sIAAAAAAAAA+NgFtrDIsWRmVeSWpSXmKPExsUixG6nosupbBxi0LvDxOJGazejxfWbM5kd
\r
48 mDyerbrF7LHl0HvmAKYoLpuU1JzMstQifbsErowLSxUKmuUqls3fzN7AuFm8i5GTQ0LAROLf
\r
49 1Q3sELaYxIV769m6GLk4hARmM0l0fD0O5WxglPjyYysLhLOUSeJWw3RGCGcJo8TS/9vB+tkE
\r
50 9CVWrJ3ECmKLCEhL7Lw7G8xmFrCUuPq1nQnEFhZwk5i3dg5QnIODRUBV4uFXIZAwL1B4T9ss
\r
51 Nogz5CQ27P7PCGJzCrhLrLkyGWyMEFDN859PWSYw8i9gZFjFKJuSW6Wbm5iZU5yarFucnJiX
\r
52 l1qka6qXm1mil5pSuokRHEguSjsYfx5UOsQowMGoxMMbscMwRIg1say4MvcQoyQHk5Io7xx2
\r
53 4xAhvqT8lMqMxOKM+KLSnNTiQ4wSHMxKIrxcv41ChHhTEiurUovyYVLSHCxK4rybfvCFCAmk
\r
54 J5akZqemFqQWwWRlODiUJHg7FIGGChalpqdWpGXmlCCkmTg4QYbzAA0/BFLDW1yQmFucmQ6R
\r
55 P8WoKCXOGwySEABJZJTmwfXCIv0VozjQK8K880GqeIBJAq77FdBgJqDBpnP0QQaXJCKkpBoY
\r
56 Lf618wt7+e+7wOyfsuCHy93MU/2vr5oxKB09ocboOvNEg1CC3Ldbf07p2kf1SaVdD+d/u/vR
\r
57 aQsR75xwvj+pKVXTJ06WPc16SuWJe/iTTJdXpxNYulmuuZhfvKeV0HM+1urMg8CrhzhYchRa
\r
58 5zj6Giz+mbzeY+n79A+127fn7FyklWKtZKCmxFKckWioxVxUnAgAlPfUXs8CAAA=
\r
59 X-BeenThere: notmuch@notmuchmail.org
\r
60 X-Mailman-Version: 2.1.13
\r
62 List-Id: "Use and development of the notmuch mail system."
\r
63 <notmuch.notmuchmail.org>
\r
64 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
65 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
66 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
67 List-Post: <mailto:notmuch@notmuchmail.org>
\r
68 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
69 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
70 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
71 X-List-Received-Date: Mon, 06 Oct 2014 23:17:39 -0000
\r
73 From: Austin Clements <amdragon@mit.edu>
\r
75 This moves the code to retrieve and clear the metadata thread ID out
\r
76 of _notmuch_database_link_message into its own function. This will
\r
77 simplify future changes.
\r
79 lib/database.cc | 69 +++++++++++++++++++++++++++++++++++----------------------
\r
80 1 file changed, 43 insertions(+), 26 deletions(-)
\r
82 diff --git a/lib/database.cc b/lib/database.cc
\r
83 index 4e68706..1c6ffc5 100644
\r
84 --- a/lib/database.cc
\r
85 +++ b/lib/database.cc
\r
86 @@ -1958,6 +1958,37 @@ _notmuch_database_link_message_to_children (notmuch_database_t *notmuch,
\r
90 +/* Fetch and clear the stored thread_id for message, or NULL if none. */
\r
92 +_consume_metadata_thread_id (void *ctx, notmuch_database_t *notmuch,
\r
93 + notmuch_message_t *message)
\r
95 + const char *message_id;
\r
97 + char *metadata_key;
\r
99 + message_id = notmuch_message_get_message_id (message);
\r
100 + metadata_key = _get_metadata_thread_id_key (ctx, message_id);
\r
102 + /* Check if we have already seen related messages to this one.
\r
103 + * If we have then use the thread_id that we stored at that time.
\r
105 + stored_id = notmuch->xapian_db->get_metadata (metadata_key);
\r
106 + if (stored_id.empty ()) {
\r
109 + Xapian::WritableDatabase *db;
\r
111 + db = static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db);
\r
113 + /* Clear the metadata for this message ID. We don't need it
\r
115 + db->set_metadata (metadata_key, "");
\r
117 + return talloc_strdup (ctx, stored_id.c_str ());
\r
121 /* Given a (mostly empty) 'message' and its corresponding
\r
122 * 'message_file' link it to existing threads in the database.
\r
124 @@ -1988,42 +2019,25 @@ _notmuch_database_link_message (notmuch_database_t *notmuch,
\r
125 notmuch_message_t *message,
\r
126 notmuch_message_file_t *message_file)
\r
128 + void *local = talloc_new (NULL);
\r
129 notmuch_status_t status;
\r
130 - const char *message_id, *thread_id = NULL;
\r
131 - char *metadata_key;
\r
132 - string stored_id;
\r
134 - message_id = notmuch_message_get_message_id (message);
\r
135 - metadata_key = _get_metadata_thread_id_key (message, message_id);
\r
137 - /* Check if we have already seen related messages to this one.
\r
138 - * If we have then use the thread_id that we stored at that time.
\r
140 - stored_id = notmuch->xapian_db->get_metadata (metadata_key);
\r
141 - if (! stored_id.empty()) {
\r
142 - Xapian::WritableDatabase *db;
\r
144 - db = static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db);
\r
146 - /* Clear the metadata for this message ID. We don't need it
\r
148 - db->set_metadata (metadata_key, "");
\r
149 - thread_id = stored_id.c_str();
\r
150 + const char *thread_id;
\r
152 - _notmuch_message_add_term (message, "thread", thread_id);
\r
154 - talloc_free (metadata_key);
\r
155 + /* Check if the message already had a thread ID */
\r
156 + thread_id = _consume_metadata_thread_id (local, notmuch, message);
\r
158 + _notmuch_message_add_term (message, "thread", thread_id);
\r
160 status = _notmuch_database_link_message_to_parents (notmuch, message,
\r
167 status = _notmuch_database_link_message_to_children (notmuch, message,
\r
173 /* If not part of any existing thread, generate a new thread ID. */
\r
174 if (thread_id == NULL) {
\r
175 @@ -2032,7 +2046,10 @@ _notmuch_database_link_message (notmuch_database_t *notmuch,
\r
176 _notmuch_message_add_term (message, "thread", thread_id);
\r
179 - return NOTMUCH_STATUS_SUCCESS;
\r
181 + talloc_free (local);
\r