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 9493B6DE1BAD for ; Sun, 5 Apr 2015 16:02:56 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: 0.529 X-Spam-Level: X-Spam-Status: No, score=0.529 tagged_above=-999 required=5 tests=[AWL=0.519, 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 lew0B-DmIy94 for ; Sun, 5 Apr 2015 16:02:55 -0700 (PDT) Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net [87.98.215.224]) by arlo.cworth.org (Postfix) with ESMTPS id 02D6A6DE1BA5 for ; Sun, 5 Apr 2015 16:02:51 -0700 (PDT) Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim 4.80) (envelope-from ) id 1YetXS-0002ou-AV; Sun, 05 Apr 2015 23:01:10 +0000 Received: (nullmailer pid 2237 invoked by uid 1000); Sun, 05 Apr 2015 22:59:24 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [WIP2 01/12] lib: Only sync modified message documents Date: Mon, 6 Apr 2015 07:59:03 +0900 Message-Id: <1428274754-1698-2-git-send-email-david@tethera.net> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1428274754-1698-1-git-send-email-david@tethera.net> References: <1428274754-1698-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: Sun, 05 Apr 2015 23:02:56 -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