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 54653431FAE for ; Mon, 25 Aug 2014 10:26:31 -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 AhTlb1CoQ49P for ; Mon, 25 Aug 2014 10:26:25 -0700 (PDT) Received: from dmz-mailsec-scanner-1.mit.edu (dmz-mailsec-scanner-1.mit.edu [18.9.25.12]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 43B71431FBC for ; Mon, 25 Aug 2014 10:26:19 -0700 (PDT) X-AuditID: 1209190c-f795e6d000006c66-ae-53fb71b93580 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) (using TLS with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP id 7F.F6.27750.9B17BF35; Mon, 25 Aug 2014 13:26:17 -0400 (EDT) Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id s7PHQE1v014412; Mon, 25 Aug 2014 13:26:14 -0400 Received: from drake.dyndns.org (31-35-14.wireless.csail.mit.edu [128.31.35.14]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s7PHQCru029617 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Mon, 25 Aug 2014 13:26:13 -0400 Received: from amthrax by drake.dyndns.org with local (Exim 4.77) (envelope-from ) id 1XLy20-0003jb-0y; Mon, 25 Aug 2014 13:26:12 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH v4 07/11] lib: Reorganize upgrade around document types Date: Mon, 25 Aug 2014 13:26:05 -0400 Message-Id: <1408987569-14146-8-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1408987569-14146-1-git-send-email-amdragon@mit.edu> References: <1408987569-14146-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrOIsWRmVeSWpSXmKPExsUixG6noruz8HewwcZWVYsbrd2MFk3TnS2u 35zJ7MDscev+a3aPZ6tuMXtsOfSeOYA5issmJTUnsyy1SN8ugStj2br3LAVPFSrOnX/A3sD4 VbKLkZNDQsBEYtmVsywQtpjEhXvr2boYuTiEBGYzSTzf2MUO4WxklDi9/wkjhHOMSeJn3wUW CGcuo8S501PB+tkENCR+31rMBGKLCEhL7Lw7mxXEZhbwklh2oR/MFhZwl9j9bxpYPYuAqsTC u5/B6nkFHCRuvLvABnGHnETDjU9gNqeAo8T0hbPBaoSAar5fPs88gZF/ASPDKkbZlNwq3dzE zJzi1GTd4uTEvLzUIl1DvdzMEr3UlNJNjKDw4pTk2cH45qDSIUYBDkYlHt4b8b+DhVgTy4or cw8xSnIwKYnyTssHCvEl5adUZiQWZ8QXleakFh9ilOBgVhLhbQbJ8aYkVlalFuXDpKQ5WJTE ed9aWwULCaQnlqRmp6YWpBbBZGU4OJQkeHMLgBoFi1LTUyvSMnNKENJMHJwgw3mAhseD1PAW FyTmFmemQ+RPMSpKifOuBdkqAJLIKM2D64XF/ytGcaBXhHmPgrTzAFMHXPcroMFMQINNe36C DC5JREhJNTDO+72384mZa3vRp+l5zn6T9z8SyFjOp+EztUWqvK9RPea9ofTK1tQWAdv1AWIc Tgobotj3tijqvDhQFMfOW8dc/6vd8m2D4IawFBW3j4dqfv3iPyl04sPcy4ujZ6xKMdLPvtHC +ky7/p+wZ5z4HyNze/0oydIDj9cHTlfefvThzd9br/S3vVViKc5INNRiLipOBACX2MKp2gIA AA== 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, 25 Aug 2014 17:26:31 -0000 Rather than potentially making multiple passes over the same type of data in the database, reorganize upgrade around each type of data that may be upgraded. This eliminates code duplication, will make multi-version upgrades faster, and will let us improve progress reporting. --- lib/database.cc | 72 +++++++++++++++++++++------------------------------------ 1 file changed, 26 insertions(+), 46 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index 525c9c3..6a7ce29 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -1248,11 +1248,9 @@ notmuch_database_upgrade (notmuch_database_t *notmuch, * format. */ notmuch->features = target_features; - /* Before version 1, each message document had its filename in the - * data field. Copy that into the new format by calling - * notmuch_message_add_filename. - */ - if (new_features & NOTMUCH_FEATURE_FILE_TERMS) { + /* Perform per-message upgrades. */ + if (new_features & + (NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER)) { notmuch_query_t *query = notmuch_query_create (notmuch, ""); notmuch_messages_t *messages; notmuch_message_t *message; @@ -1271,13 +1269,27 @@ notmuch_database_upgrade (notmuch_database_t *notmuch, message = notmuch_messages_get (messages); - filename = _notmuch_message_talloc_copy_data (message); - if (filename && *filename != '\0') { - _notmuch_message_add_filename (message, filename); - _notmuch_message_clear_data (message); - _notmuch_message_sync (message); + /* Before version 1, each message document had its + * filename in the data field. Copy that into the new + * format by calling notmuch_message_add_filename. + */ + if (new_features & NOTMUCH_FEATURE_FILE_TERMS) { + filename = _notmuch_message_talloc_copy_data (message); + if (filename && *filename != '\0') { + _notmuch_message_add_filename (message, filename); + _notmuch_message_clear_data (message); + } + talloc_free (filename); } - talloc_free (filename); + + /* Prior to version 2, the "folder:" prefix was + * probabilistic and stemmed. Change it to the current + * boolean prefix. Add "path:" prefixes while at it. + */ + if (new_features & NOTMUCH_FEATURE_BOOL_FOLDER) + _notmuch_message_upgrade_folder (message); + + _notmuch_message_sync (message); notmuch_message_destroy (message); @@ -1287,7 +1299,9 @@ notmuch_database_upgrade (notmuch_database_t *notmuch, notmuch_query_destroy (query); } - /* Also, before version 1 we stored directory timestamps in + /* Perform per-directory upgrades. */ + + /* Before version 1 we stored directory timestamps in * XTIMESTAMP documents instead of the current XDIRECTORY * documents. So copy those as well. */ if (new_features & NOTMUCH_FEATURE_DIRECTORY_DOCS) { @@ -1329,40 +1343,6 @@ notmuch_database_upgrade (notmuch_database_t *notmuch, } } - /* - * Prior to version 2, the "folder:" prefix was probabilistic and - * stemmed. Change it to the current boolean prefix. Add "path:" - * prefixes while at it. - */ - if (new_features & NOTMUCH_FEATURE_BOOL_FOLDER) { - notmuch_query_t *query = notmuch_query_create (notmuch, ""); - notmuch_messages_t *messages; - notmuch_message_t *message; - - count = 0; - total = notmuch_query_count_messages (query); - - for (messages = notmuch_query_search_messages (query); - notmuch_messages_valid (messages); - notmuch_messages_move_to_next (messages)) { - if (do_progress_notify) { - progress_notify (closure, (double) count / total); - do_progress_notify = 0; - } - - message = notmuch_messages_get (messages); - - _notmuch_message_upgrade_folder (message); - _notmuch_message_sync (message); - - notmuch_message_destroy (message); - - count++; - } - - notmuch_query_destroy (query); - } - db->set_metadata ("features", _print_features (local, notmuch->features)); db->set_metadata ("version", STRINGIFY (NOTMUCH_DATABASE_VERSION)); -- 2.0.0