From 2c668aa7fcb8b939908d74c0a1e1379fb3d86ea1 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 14 Oct 2014 02:20:00 +2000 Subject: [PATCH] [WIP PATCH 1/4] lib: Only sync modified message documents --- f8/df11d0939914b6ca19b340e6203c2f7cf8b436 | 159 ++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 f8/df11d0939914b6ca19b340e6203c2f7cf8b436 diff --git a/f8/df11d0939914b6ca19b340e6203c2f7cf8b436 b/f8/df11d0939914b6ca19b340e6203c2f7cf8b436 new file mode 100644 index 000000000..dd513e89d --- /dev/null +++ b/f8/df11d0939914b6ca19b340e6203c2f7cf8b436 @@ -0,0 +1,159 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by olra.theworths.org (Postfix) with ESMTP id 19362431FD8 + for ; Sun, 12 Oct 2014 23:20:26 -0700 (PDT) +X-Virus-Scanned: Debian amavisd-new at olra.theworths.org +X-Spam-Flag: NO +X-Spam-Score: -2.3 +X-Spam-Level: +X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5 + tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled +Received: from olra.theworths.org ([127.0.0.1]) + by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id mq5YbDnu2QYv for ; + Sun, 12 Oct 2014 23:20:18 -0700 (PDT) +Received: from dmz-mailsec-scanner-6.mit.edu (dmz-mailsec-scanner-6.mit.edu + [18.7.68.35]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 7E3C2431FBD + for ; Sun, 12 Oct 2014 23:20:14 -0700 (PDT) +X-AuditID: 12074423-f799d6d00000337c-0b-543b6f1c3870 +Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) + (using TLS with cipher AES256-SHA (256/256 bits)) + (Client did not present a certificate) + by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP + id BF.74.13180.C1F6B345; Mon, 13 Oct 2014 02:20:12 -0400 (EDT) +Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) + by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id s9D6K8wt019181; + Mon, 13 Oct 2014 02:20:08 -0400 +Received: from drake.dyndns.org ([73.162.189.21]) (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s9D6K5Ve031972 + (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); + Mon, 13 Oct 2014 02:20:07 -0400 +Received: from amthrax by drake.dyndns.org with local (Exim 4.84) + (envelope-from ) + id 1XdYzF-0000U8-8L; Mon, 13 Oct 2014 02:20:05 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [WIP PATCH 1/4] lib: Only sync modified message documents +Date: Mon, 13 Oct 2014 02:20:00 -0400 +Message-Id: <1413181203-1676-2-git-send-email-aclements@csail.mit.edu> +X-Mailer: git-send-email 2.1.0 +In-Reply-To: <1413181203-1676-1-git-send-email-aclements@csail.mit.edu> +References: <1413181203-1676-1-git-send-email-aclements@csail.mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsUixG6nriuTbx1i0Phc3eL6zZnMDowez1bd + Yg5gjOKySUnNySxLLdK3S+DKaJ6yjL1gj1jFm5lHmRoYfwp2MXJySAiYSOy7cosNwhaTuHBv + PZDNxSEkMJtJ4vfZ21DORkaJtXdgnOVMEt9erWeFcJYwSpxq6GUF6WcT0JdYsXYSmC0iIC2x + 8+5sIJuDg1lATeJPlwqIKSzgJPFvtQ5IBYuAqkTbrxcsIGFeATeJTb8DIY6Qk9iw+z8jiM0p + 4C5xceJZZhBbCKjkWNs1lgmM/AsYGVYxyqbkVunmJmbmFKcm6xYnJ+blpRbpmunlZpbopaaU + bmIEh4yL8g7GPweVDjEKcDAq8fBa/rEKEWJNLCuuzD3EKMnBpCTKG5BmHSLEl5SfUpmRWJwR + X1Sak1p8iFGCg1lJhPetDVCONyWxsiq1KB8mJc3BoiTOu+kHX4iQQHpiSWp2ampBahFMVoaD + Q0mCVz0PqFGwKDU9tSItM6cEIc3EwQkynAdoeEsOyPDigsTc4sx0iPwpRkUpcd7vuUAJAZBE + RmkeXC8spl8xigO9IswbB7KCB5gO4LpfAQ1mAhp8tMscZHBJIkJKqoHRKvn1kWvVgTzq29VT + znlHTdfc9OtsTXB7vKLjogk6urG7nj8zrfAR60+o0FirNtmN0znkvf+dQq9c/a3Pwy+1lCdc + 3OWcy5R/1NpBofE2j7qBdATLFFblOWvNNqxTdte9wnE9NIL56sStt5eWXrqrWtYmmxy1dUXo + zSvcx7paObLk9x5bpqPEUpyRaKjFXFScCAAjIfjwxAIAAA== +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.13 +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: Mon, 13 Oct 2014 06:20:26 -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 a7a13cc..cf2fd7c 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; + }; +@@ -538,6 +541,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. */ + } +@@ -791,6 +795,7 @@ void + _notmuch_message_clear_data (notmuch_message_t *message) + { + message->doc.set_data (""); ++ message->modified = TRUE; + } + + static void +@@ -988,6 +993,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. */ +@@ -999,8 +1005,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. */ +@@ -1075,6 +1085,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); + +@@ -1143,6 +1154,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.0 + -- 2.26.2