From: David Bremner Date: Fri, 5 Jun 2015 17:28:33 +0000 (+0200) Subject: [PATCH 1/6] lib: Only sync modified message documents X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=0eaf2686456aa4c2a930a7af2297c072d7018543;p=notmuch-archives.git [PATCH 1/6] lib: Only sync modified message documents --- diff --git a/c6/6a2e3272e3ba4a02ed65f7e18d7a985c8241f4 b/c6/6a2e3272e3ba4a02ed65f7e18d7a985c8241f4 new file mode 100644 index 000000000..b5402d682 --- /dev/null +++ b/c6/6a2e3272e3ba4a02ed65f7e18d7a985c8241f4 @@ -0,0 +1,133 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id D85946DE1785 + for ; Fri, 5 Jun 2015 10:31:09 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: 0.237 +X-Spam-Level: +X-Spam-Status: No, score=0.237 tagged_above=-999 required=5 tests=[AWL=0.227, + T_HEADER_FROM_DIFFERENT_DOMAINS=0.01] autolearn=disabled +Received: from arlo.cworth.org ([127.0.0.1]) + by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id JkPuUjrYLOn0 for ; + Fri, 5 Jun 2015 10:31:07 -0700 (PDT) +Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net + [87.98.215.224]) + by arlo.cworth.org (Postfix) with ESMTPS id 2AA5D6DE17E8 + for ; Fri, 5 Jun 2015 10:31:01 -0700 (PDT) +Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim + 4.80) (envelope-from ) + id 1Z0vQl-0002nX-CW; Fri, 05 Jun 2015 17:29:19 +0000 +Received: (nullmailer pid 24248 invoked by uid 1000); Fri, 05 Jun 2015 + 17:28:42 -0000 +From: David Bremner +To: notmuch@notmuchmail.org +Subject: [PATCH 1/6] lib: Only sync modified message documents +Date: Fri, 5 Jun 2015 19:28:33 +0200 +Message-Id: <1433525318-23756-2-git-send-email-david@tethera.net> +X-Mailer: git-send-email 2.1.4 +In-Reply-To: <1433525318-23756-1-git-send-email-david@tethera.net> +References: <1432936375-astroid-4-0i1n6yczs2-1520@strange> + <1433525318-23756-1-git-send-email-david@tethera.net> +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.18 +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, 05 Jun 2015 17:31:10 -0000 + +From: Austin Clements + +Previously, we updated the database copy of a message on every call to +_notmuch_message_sync, even if nothing had changed. In particular, +this always happens on a thaw, so a freeze/thaw pair with no +modifications between still caused a database update. + +We only modify message documents in a handful of places, so keep track +of whether the document has been modified and only sync it when +necessary. This will be particularly important when we add message +revision tracking. +--- + lib/message.cc | 12 ++++++++++++ + 1 file changed, 12 insertions(+) + +diff --git a/lib/message.cc b/lib/message.cc +index 5bc7aff..1ddce3c 100644 +--- a/lib/message.cc ++++ b/lib/message.cc +@@ -43,6 +43,9 @@ struct visible _notmuch_message { + * if each flag has been initialized. */ + unsigned long lazy_flags; + ++ /* Message document modified since last sync */ ++ notmuch_bool_t modified; ++ + Xapian::Document doc; + Xapian::termcount termpos; + }; +@@ -539,6 +542,7 @@ _notmuch_message_remove_terms (notmuch_message_t *message, const char *prefix) + + try { + message->doc.remove_term ((*i)); ++ message->modified = TRUE; + } catch (const Xapian::InvalidArgumentError) { + /* Ignore failure to remove non-existent term. */ + } +@@ -793,6 +797,7 @@ void + _notmuch_message_clear_data (notmuch_message_t *message) + { + message->doc.set_data (""); ++ message->modified = TRUE; + } + + static void +@@ -990,6 +995,7 @@ _notmuch_message_set_header_values (notmuch_message_t *message, + Xapian::sortable_serialise (time_value)); + message->doc.add_value (NOTMUCH_VALUE_FROM, from); + message->doc.add_value (NOTMUCH_VALUE_SUBJECT, subject); ++ message->modified = TRUE; + } + + /* Synchronize changes made to message->doc out into the database. */ +@@ -1001,8 +1007,12 @@ _notmuch_message_sync (notmuch_message_t *message) + if (message->notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY) + return; + ++ if (! message->modified) ++ return; ++ + db = static_cast (message->notmuch->xapian_db); + db->replace_document (message->doc_id, message->doc); ++ message->modified = FALSE; + } + + /* Delete a message document from the database. */ +@@ -1077,6 +1087,7 @@ _notmuch_message_add_term (notmuch_message_t *message, + return NOTMUCH_PRIVATE_STATUS_TERM_TOO_LONG; + + message->doc.add_term (term, 0); ++ message->modified = TRUE; + + talloc_free (term); + +@@ -1145,6 +1156,7 @@ _notmuch_message_remove_term (notmuch_message_t *message, + + try { + message->doc.remove_term (term); ++ message->modified = TRUE; + } catch (const Xapian::InvalidArgumentError) { + /* We'll let the philosopher's try to wrestle with the + * question of whether failing to remove that which was not +-- +2.1.4 +