[PATCH 4/5] Add the file name list to the unified message metadata pass.
authorAustin Clements <amdragon@MIT.EDU>
Thu, 9 Dec 2010 20:59:55 +0000 (15:59 +1900)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:37:39 +0000 (09:37 -0800)
ec/dcc24f3b8aede41875707c2fe1116c357f435f [new file with mode: 0644]

diff --git a/ec/dcc24f3b8aede41875707c2fe1116c357f435f b/ec/dcc24f3b8aede41875707c2fe1116c357f435f
new file mode 100644 (file)
index 0000000..08a6837
--- /dev/null
@@ -0,0 +1,209 @@
+Return-Path: <amthrax@awakening.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 D20C3431FB6\r
+       for <notmuch@notmuchmail.org>; Thu,  9 Dec 2010 13:00:44 -0800 (PST)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       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 VIL38PYfZ7fM for <notmuch@notmuchmail.org>;\r
+       Thu,  9 Dec 2010 13:00:42 -0800 (PST)\r
+Received: from dmz-mailsec-scanner-6.mit.edu (DMZ-MAILSEC-SCANNER-6.MIT.EDU\r
+       [18.7.68.35])\r
+       by olra.theworths.org (Postfix) with ESMTP id BAF1941A557\r
+       for <notmuch@notmuchmail.org>; Thu,  9 Dec 2010 13:00:35 -0800 (PST)\r
+X-AuditID: 12074423-b7bd0ae000000a00-b8-4d01437397a7\r
+Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])\r
+       by dmz-mailsec-scanner-6.mit.edu (Symantec Brightmail Gateway) with\r
+       SMTP id 07.2A.02560.373410D4; Thu,  9 Dec 2010 16:00:35 -0500 (EST)\r
+Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])\r
+       by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id oB9L0Zh0011388; \r
+       Thu, 9 Dec 2010 16:00:35 -0500\r
+Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91])\r
+       (authenticated bits=0)\r
+       (User authenticated as amdragon@ATHENA.MIT.EDU)\r
+       by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id oB9L0Y4U010114\r
+       (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);\r
+       Thu, 9 Dec 2010 16:00:35 -0500 (EST)\r
+Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.72)\r
+       (envelope-from <amthrax@awakening.csail.mit.edu>)\r
+       id 1PQnbO-0007Hv-42; Thu, 09 Dec 2010 16:00:34 -0500\r
+From: Austin Clements <amdragon@MIT.EDU>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 4/5] Add the file name list to the unified message metadata\r
+       pass.\r
+Date: Thu,  9 Dec 2010 15:59:55 -0500\r
+Message-Id: <1291928396-27937-5-git-send-email-amdragon@mit.edu>\r
+X-Mailer: git-send-email 1.7.2.3\r
+In-Reply-To: <1291928396-27937-1-git-send-email-amdragon@mit.edu>\r
+References: <1291928396-27937-1-git-send-email-amdragon@mit.edu>\r
+X-Brightmail-Tracker: AAAAARbjX5o=\r
+Cc: Austin Clements <amdragon@mit.edu>\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, 09 Dec 2010 21:00:45 -0000\r
+\r
+Even if the caller never uses the file names, there is little cost to\r
+simply fetching the file name terms.  However, retrieving the full\r
+paths requires additional database work, so the expansion from terms\r
+to full paths is performed lazily.\r
+\r
+This also simplifies clearing the filename cache, since that's now\r
+handled by the generic metadata cache code.\r
+\r
+This further reduces my inbox search from 3.102 seconds before the\r
+unified metadata pass to 2.206 seconds (1.4X faster).\r
+---\r
+ lib/message.cc |   52 +++++++++++++++++++++++++++++-----------------------\r
+ 1 files changed, 29 insertions(+), 23 deletions(-)\r
+\r
+diff --git a/lib/message.cc b/lib/message.cc\r
+index dbf683c..adb205f 100644\r
+--- a/lib/message.cc\r
++++ b/lib/message.cc\r
+@@ -32,6 +32,7 @@ struct _notmuch_message {\r
+     char *message_id;\r
+     char *thread_id;\r
+     char *in_reply_to;\r
++    notmuch_string_list_t *filename_term_list;\r
+     notmuch_string_list_t *filename_list;\r
+     char *author;\r
+     notmuch_message_file_t *message_file;\r
+@@ -101,6 +102,7 @@ _notmuch_message_create_for_document (const void *talloc_owner,\r
+     message->message_id = NULL;\r
+     message->thread_id = NULL;\r
+     message->in_reply_to = NULL;\r
++    message->filename_term_list = NULL;\r
+     message->filename_list = NULL;\r
+     message->message_file = NULL;\r
+     message->author = NULL;\r
+@@ -292,6 +294,7 @@ _notmuch_message_ensure_metadata (notmuch_message_t *message)\r
+     Xapian::TermIterator i, end;\r
+     const char *thread_prefix = _find_prefix ("thread"),\r
+       *id_prefix = _find_prefix ("id"),\r
++      *filename_prefix = _find_prefix ("file-direntry"),\r
+       *replyto_prefix = _find_prefix ("replyto");\r
\r
+     /* We do this all in a single pass because Xapian decompresses the\r
+@@ -314,8 +317,16 @@ _notmuch_message_ensure_metadata (notmuch_message_t *message)\r
+       message->message_id =\r
+           _notmuch_message_get_term (message, i, end, id_prefix);\r
\r
++    /* Get filename list.  Here we get only the terms.  We lazily\r
++     * expand them to full file names when needed in\r
++     * _notmuch_message_ensure_filename_list. */\r
++    assert (strcmp (id_prefix, filename_prefix) < 0);\r
++    if (!message->filename_term_list && !message->filename_list)\r
++      message->filename_term_list =\r
++          _notmuch_get_terms_with_prefix (message, i, end, filename_prefix);\r
++\r
+     /* Get reply to */\r
+-    assert (strcmp (id_prefix, replyto_prefix) < 0);\r
++    assert (strcmp (filename_prefix, replyto_prefix) < 0);\r
+     if (!message->in_reply_to)\r
+       message->in_reply_to =\r
+           _notmuch_message_get_term (message, i, end, replyto_prefix);\r
+@@ -334,6 +345,12 @@ _notmuch_message_invalidate_metadata (notmuch_message_t *message,\r
+       message->thread_id = NULL;\r
+     }\r
\r
++    if (strcmp ("file-direntry", prefix_name) == 0) {\r
++      talloc_free (message->filename_term_list);\r
++      talloc_free (message->filename_list);\r
++      message->filename_term_list = message->filename_list = NULL;\r
++    }\r
++\r
+     if (strcmp ("replyto", prefix_name) == 0) {\r
+       talloc_free (message->in_reply_to);\r
+       message->in_reply_to = NULL;\r
+@@ -433,11 +450,6 @@ _notmuch_message_add_filename (notmuch_message_t *message,\r
+     void *local = talloc_new (message);\r
+     char *direntry;\r
\r
+-    if (message->filename_list) {\r
+-      talloc_free (message->filename_list);\r
+-      message->filename_list = NULL;\r
+-    }\r
+-\r
+     if (filename == NULL)\r
+       INTERNAL_ERROR ("Message filename cannot be NULL.");\r
\r
+@@ -504,21 +516,18 @@ _notmuch_message_clear_data (notmuch_message_t *message)\r
+ static void\r
+ _notmuch_message_ensure_filename_list (notmuch_message_t *message)\r
+ {\r
+-    const char *prefix = _find_prefix ("file-direntry");\r
+-    int prefix_len = strlen (prefix);\r
+-    Xapian::TermIterator i;\r
++    notmuch_string_node_t *node;\r
\r
+     if (message->filename_list)\r
+       return;\r
\r
+-    message->filename_list = _notmuch_string_list_create (message);\r
++    if (!message->filename_term_list)\r
++      _notmuch_message_ensure_metadata (message);\r
\r
+-    i = message->doc.termlist_begin ();\r
+-    i.skip_to (prefix);\r
++    message->filename_list = _notmuch_string_list_create (message);\r
++    node = message->filename_term_list->head;\r
\r
+-    if (i == message->doc.termlist_end () ||\r
+-      strncmp ((*i).c_str (), prefix, prefix_len))\r
+-    {\r
++    if (!node) {\r
+       /* A message document created by an old version of notmuch\r
+        * (prior to rename support) will have the filename in the\r
+        * data of the document rather than as a file-direntry term.\r
+@@ -537,19 +546,13 @@ _notmuch_message_ensure_filename_list (notmuch_message_t *message)\r
+       return;\r
+     }\r
\r
+-    for (; i != message->doc.termlist_end (); i++) {\r
++    for (; node; node = node->next) {\r
+       void *local = talloc_new (message);\r
+       const char *db_path, *directory, *basename, *filename;\r
+       char *colon, *direntry = NULL;\r
+       unsigned int directory_id;\r
\r
+-      /* Terminate loop at first term without desired prefix. */\r
+-      if (strncmp ((*i).c_str (), prefix, prefix_len))\r
+-          break;\r
+-\r
+-      direntry = talloc_strdup (local, (*i).c_str ());\r
+-\r
+-      direntry += prefix_len;\r
++      direntry = node->string;\r
\r
+       directory_id = strtol (direntry, &colon, 10);\r
\r
+@@ -577,6 +580,9 @@ _notmuch_message_ensure_filename_list (notmuch_message_t *message)\r
\r
+       talloc_free (local);\r
+     }\r
++\r
++    talloc_free (message->filename_term_list);\r
++    message->filename_term_list = NULL;\r
+ }\r
\r
+ const char *\r
+-- \r
+1.7.2.3\r
+\r