--- /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 CA3AC431FBD\r
+ for <notmuch@notmuchmail.org>; Mon, 6 Oct 2014 16:17:42 -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 QEdN+9r3Ua9Y for <notmuch@notmuchmail.org>;\r
+ Mon, 6 Oct 2014 16:17:42 -0700 (PDT)\r
+Received: from dmz-mailsec-scanner-2.mit.edu (dmz-mailsec-scanner-2.mit.edu\r
+ [18.9.25.13])\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 F0187431FC2\r
+ for <notmuch@notmuchmail.org>; Mon, 6 Oct 2014 16:17:30 -0700 (PDT)\r
+X-AuditID: 1209190d-f79c06d000006f95-0d-5433230a1b4e\r
+Received: from mailhub-auth-3.mit.edu ( [18.9.21.43])\r
+ (using TLS with cipher AES256-SHA (256/256 bits))\r
+ (Client did not present a certificate)\r
+ by dmz-mailsec-scanner-2.mit.edu (Symantec Messaging Gateway) with SMTP\r
+ id 44.74.28565.A0323345; Mon, 6 Oct 2014 19:17:30 -0400 (EDT)\r
+Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
+ by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id s96NHPmP030744; \r
+ Mon, 6 Oct 2014 19:17:25 -0400\r
+Received: from drake.dyndns.org ([12.185.136.2]) (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 s96NHNfm014477\r
+ (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT);\r
+ Mon, 6 Oct 2014 19:17:24 -0400\r
+Received: from amthrax by drake.dyndns.org with local (Exim 4.84)\r
+ (envelope-from <aclements@csail.mit.edu>)\r
+ id 1XbHWs-0001K4-EG; Mon, 06 Oct 2014 17:17:22 -0600\r
+From: Austin Clements <aclements@csail.mit.edu>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH v2 12/12] lib: Remove unnecessary thread linking steps when\r
+ using ghost messages\r
+Date: Mon, 6 Oct 2014 17:17:18 -0600\r
+Message-Id: <1412637438-4821-13-git-send-email-aclements@csail.mit.edu>\r
+X-Mailer: git-send-email 2.1.0\r
+In-Reply-To: <1412637438-4821-1-git-send-email-aclements@csail.mit.edu>\r
+References: <1412637438-4821-1-git-send-email-aclements@csail.mit.edu>\r
+X-Brightmail-Tracker:\r
+ H4sIAAAAAAAAA+NgFtrLIsWRmVeSWpSXmKPExsUixCmqrculbBxicPauvsWN1m5Gi+s3ZzI7\r
+ MHk8W3WL2WPLoffMAUxRXDYpqTmZZalF+nYJXBm3zn9gKnjFW3FwczdbA+Mbri5GTg4JAROJ\r
+ qydnsEHYYhIX7q0Hsrk4hARmM0ksXfaaEcLZwCgxd/dkJghnKZPE7Pk9UM4SRokD8/rZQfrZ\r
+ BPQlVqydxApiiwhIS+y8OxvMZhawlLj6tZ0JxBYWSJBY3rsZKM7BwSKgKtFx1REkzCvgLtG6\r
+ fD87xBlyEht2/2cEsTmB4muuTAYbIyTgJvH851OWCYz8CxgZVjHKpuRW6eYmZuYUpybrFicn\r
+ 5uWlFuka6eVmluilppRuYgSHkiTvDsZ3B5UOMQpwMCrx8EbsMAwRYk0sK67MPcQoycGkJMo7\r
+ h904RIgvKT+lMiOxOCO+qDQntfgQowQHs5IIL9dvoxAh3pTEyqrUonyYlDQHi5I476YffCFC\r
+ AumJJanZqakFqUUwWRkODiUJXmMloKGCRanpqRVpmTklCGkmDk6Q4TxAw/8pAtXwFhck5hZn\r
+ pkPkTzEqSonzBoMkBEASGaV5cL2wWH/FKA70ijBvEMgKHmCagOt+BTSYCWiw6Rx9kMEliQgp\r
+ qQbGzBNHD8xVXrTmvWRw0hnJPRv/TNT6et6EP1zi6XST86zb7P2NdlRVqa+8eG7rv+83o2pe\r
+ rp06VyXgjLb6o8gbRhxaGXXV6im+dpYXrv6K5Th6hG/9sV3ZurcXTOcONFZmSr5qujx/7+U5\r
+ a1j3+DU94rTvsEkXn/6Cb/P9tV8zrz9MZw45//jSGiWW4oxEQy3mouJEAHPzeZbQAgAA\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: Mon, 06 Oct 2014 23:17:43 -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 | 21 +++++++++++++++++----\r
+ 1 file changed, 17 insertions(+), 4 deletions(-)\r
+\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index 1316529..6e51a72 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -2169,10 +2169,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