--- /dev/null
+Return-Path: <aclements@csail.mit.edu>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by olra.theworths.org (Postfix) with ESMTP id 1D044431FD4\r
+ for <notmuch@notmuchmail.org>; Thu, 23 Oct 2014 05:31:40 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -2.3\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
+ tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+ by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id 1jXNvTE9oDqe for <notmuch@notmuchmail.org>;\r
+ Thu, 23 Oct 2014 05:31:34 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-8.mit.edu (dmz-mailsec-scanner-8.mit.edu\r
+ [18.7.68.37])\r
+ (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+ (No client certificate requested)\r
+ by olra.theworths.org (Postfix) with ESMTPS id 162E5429E2E\r
+ for <notmuch@notmuchmail.org>; Thu, 23 Oct 2014 05:31:01 -0700 (PDT)\r
+X-AuditID: 12074425-f79e46d000002583-b4-5448f5043af0\r
+Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
+ (using TLS with cipher AES256-SHA (256/256 bits))\r
+ (Client did not present a certificate)\r
+ by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id E0.05.09603.405F8445; Thu, 23 Oct 2014 08:31:00 -0400 (EDT)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+ by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id s9NCUtUc030515; \r
+ Thu, 23 Oct 2014 08:30:56 -0400\r
+Received: from drake.dyndns.org\r
+ (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com\r
+ [216.15.114.40]) (authenticated bits=0)\r
+ (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+ by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s9NCUsUX008990\r
+ (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT);\r
+ Thu, 23 Oct 2014 08:30:55 -0400\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.84)\r
+ (envelope-from <aclements@csail.mit.edu>)\r
+ id 1XhHXU-0007cG-Mp; Thu, 23 Oct 2014 08:30:48 -0400\r
+From: Austin Clements <aclements@csail.mit.edu>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v3 9/9] lib: Remove unnecessary thread linking steps when\r
+ using ghost messages\r
+Date: Thu, 23 Oct 2014 08:30:41 -0400\r
+Message-Id: <1414067441-29054-10-git-send-email-aclements@csail.mit.edu>\r
+X-Mailer: git-send-email 2.1.0\r
+In-Reply-To: <1414067441-29054-1-git-send-email-aclements@csail.mit.edu>\r
+References: <1414067441-29054-1-git-send-email-aclements@csail.mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrLIsWRmVeSWpSXmKPExsUixG6nrsvy1SPEYGmnicXquTwW12/OZHZg\r
+ 8tg56y67x7NVt5gDmKK4bFJSczLLUov07RK4Mq6tOMFasFC0ov9DK1sD40uBLkZODgkBE4m+\r
+ P++YIGwxiQv31rN1MXJxCAnMZpL4taSLCcLZyCix+cxmFgjnDpPE9fVHGCGcJYwScy60s4P0\r
+ swnoS6xYO4kVxBYRkJbYeXc2mM0s4Cjxef8iNhBbWCBO4uipQ2D1LAKqEp0Le8HivAIeEk+v\r
+ H2WEuENOYsPu/2A2J1B8z447YDVCAu4S258fZJ3AyL+AkWEVo2xKbpVubmJmTnFqsm5xcmJe\r
+ XmqRroVebmaJXmpK6SZGcCi5qO5gnHBI6RCjAAejEg/vhVSPECHWxLLiytxDjJIcTEqivDEP\r
+ gEJ8SfkplRmJxRnxRaU5qcWHGCU4mJVEeOMvAOV4UxIrq1KL8mFS0hwsSuK8m37whQgJpCeW\r
+ pGanphakFsFkZTg4lCR4Gb8ANQoWpaanVqRl5pQgpJk4OEGG8wANv/UZZHhxQWJucWY6RP4U\r
+ o6KUOG8ySEIAJJFRmgfXC4v1V4ziQK8I86qBrOABpgm47ldAg5lArt4ANrgkESEl1cBopu+1\r
+ XjCQ+3mi1gGJa59W1ScLnGmfvP0QX81z++aMRVfScx7r7T34/P0VtglKS3i/xYXxfZpRMrHC\r
+ T+NteffTxV2ycRvYF8ydKSSUFeG0tvhCC8Ozmv5drHWF9zXdmg+sdNGW11kxk5ftuKulgedJ\r
+ Hrkq1rKcSnvlsHzP27MSgw/1/fEsuKDEUpyRaKjFXFScCAC9dw+W0AIAAA==\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Thu, 23 Oct 2014 12:31:40 -0000\r
+\r
+From: Austin Clements <amdragon@mit.edu>\r
+\r
+Previously, it was necessary to link new messages to children to work\r
+around some (though not all) problems with the old metadata-based\r
+approach to stored thread IDs. With ghost messages, this is no longer\r
+necessary, so don't bother with child linking when ghost messages are\r
+in use.\r
+---\r
+ lib/database.cc | 29 +++++++++++++++++++++--------\r
+ 1 file changed, 21 insertions(+), 8 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index b673718..3601f9d 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -2136,11 +2136,11 @@ _consume_metadata_thread_id (void *ctx, notmuch_database_t *notmuch,\r
+ * reference 'message'.\r
+ *\r
+ * In all cases, we assign to the current message the first thread ID\r
+- * found (through either parent or child). We will also merge any\r
+- * existing, distinct threads where this message belongs to both,\r
+- * (which is not uncommon when messages are processed out of order).\r
++ * found. We will also merge any existing, distinct threads where this\r
++ * message belongs to both, (which is not uncommon when messages are\r
++ * processed out of order).\r
+ *\r
+- * Finally, if no thread ID has been found through parent or child, we\r
++ * Finally, if no thread ID has been found through referenced messages, we\r
+ * call _notmuch_message_generate_thread_id to generate a new thread\r
+ * ID. This should only happen for new, top-level messages, (no\r
+ * References or In-Reply-To header in this message, and no previously\r
+@@ -2172,10 +2172,23 @@ _notmuch_database_link_message (notmuch_database_t *notmuch,\r
+ if (status)\r
+ goto DONE;\r
+ \r
+- status = _notmuch_database_link_message_to_children (notmuch, message,\r
+- &thread_id);\r
+- if (status)\r
+- goto DONE;\r
++ if (! (notmuch->features & NOTMUCH_FEATURE_GHOSTS)) {\r
++ /* In general, it shouldn't be necessary to link children,\r
++ * since the earlier indexing of those children will have\r
++ * stored a thread ID for the missing parent. However, prior\r
++ * to ghost messages, these stored thread IDs were NOT\r
++ * rewritten during thread merging (and there was no\r
++ * performant way to do so), so if indexed children were\r
++ * pulled into a different thread ID by a merge, it was\r
++ * necessary to pull them *back* into the stored thread ID of\r
++ * the parent. With ghost messages, we just rewrite the\r
++ * stored thread IDs during merging, so this workaround isn't\r
++ * necessary. */\r
++ status = _notmuch_database_link_message_to_children (notmuch, message,\r
++ &thread_id);\r
++ if (status)\r
++ goto DONE;\r
++ }\r
+ \r
+ /* If not part of any existing thread, generate a new thread ID. */\r
+ if (thread_id == NULL) {\r
+-- \r
+2.1.0\r
+\r