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 84DD3429E2B for ; Sat, 11 Jun 2011 13:07:27 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 OnsD6EdvPy4E for ; Sat, 11 Jun 2011 13:07:27 -0700 (PDT) Received: from dmz-mailsec-scanner-3.mit.edu (DMZ-MAILSEC-SCANNER-3.MIT.EDU [18.9.25.14]) by olra.theworths.org (Postfix) with ESMTP id D6F46431FB6 for ; Sat, 11 Jun 2011 13:07:26 -0700 (PDT) X-AuditID: 1209190e-b7c39ae000000a8c-b9-4df3caedecc7 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP id 09.7A.02700.DEAC3FD4; Sat, 11 Jun 2011 16:07:09 -0400 (EDT) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id p5BK7QrI030878; Sat, 11 Jun 2011 16:07:26 -0400 Received: from drake.mit.edu (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com [209.6.116.242]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id p5BK7PAn006058 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sat, 11 Jun 2011 16:07:26 -0400 (EDT) Received: from amthrax by drake.mit.edu with local (Exim 4.76) (envelope-from ) id 1QVUSr-0000Ie-69; Sat, 11 Jun 2011 16:07:25 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 15/17] new: Synchronize maildir flags eagerly. Date: Sat, 11 Jun 2011 16:04:41 -0400 Message-Id: <1307822683-848-16-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.5.1 In-Reply-To: <1307822683-848-1-git-send-email-amdragon@mit.edu> References: <87ei34rnc5.fsf@yoom.home.cworth.org> <1307822683-848-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrPIsWRmVeSWpSXmKPExsUixG6novv21Gdfg4Y2MYvrN2cyOzB6PFt1 izmAMYrLJiU1J7MstUjfLoEr48zlc4wFb+QrPs+cwtTA+EKyi5GTQ0LAROJk8xwmCFtM4sK9 9WxdjFwcQgL7GCWmbpnGDOFsYJQ49nIqE4Rzn0libcd/KGc+o8TdfU3sIP1sAhoS2/YvZwSx RQSkJXbenc3axcjBwSygJvGnSwUkLCxgJ/F7xXdWEJtFQFXi+ff3YK28AvYSV+Z/YYU4Q0Hi ypV5LCA2J1B83sGrYLaQQJrEklu72Scw8i9gZFjFKJuSW6Wbm5iZU5yarFucnJiXl1qka6yX m1mil5pSuokRFDacknw7GL8eVDrEKMDBqMTDq7f2s68Qa2JZcWXuIUZJDiYlUV6dE0AhvqT8 lMqMxOKM+KLSnNTiQ4wSHMxKIrzr2z/5CvGmJFZWpRblw6SkOViUxHlnSqr7CgmkJ5akZqem FqQWwWRlODiUJHglgfEhJFiUmp5akZaZU4KQZuLgBBnOAzT86EmgGt7igsTc4sx0iPwpRl2O xxs2HWIUYsnLz0uVEudVBxkkAFKUUZoHNwcW768YxYHeEub9ATKKB5gq4Ca9AlrCBLREoBRs SUkiQkqqgVFpQeikjU+ZOhm2/WibJ5Oxstvjzc6Zd5XOzNI6+3LaorW7rVUPPj2zZ8nXN24Z +ilnbfNecfPs3nztukXnXdfQ84lxSYbch5sSF9+dbhxY9vYEgzOv+PyWSr9p3mub9oS79ZxP axZ49e10Dk+EG9+N9yvfx9hOnrYvPkbJ63/zmaW2x9Jutz1XYinOSDTUYi4qTgQAUrt5ZdIC AAA= Cc: Austin Clements 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: Sat, 11 Jun 2011 20:07:27 -0000 Because flag synchronization is stateless, it can be performed at any time as long as it's guaranteed to be performed after any change to a message's filename list. Take advantage of this to synchronize tags immediately after a filename is added or removed. This does not yet make adding or removing a message atomic, but it is a big step toward atomicity because it reduces the window where the database tags are inconsistent from nearly the entire notmuch-new to just around when the message is added or removed. --- notmuch-new.c | 42 ++++++++---------------------------------- 1 files changed, 8 insertions(+), 34 deletions(-) diff --git a/notmuch-new.c b/notmuch-new.c index dc349f6..b24eb51 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -50,7 +50,6 @@ typedef struct { _filename_list_t *directory_mtimes; notmuch_bool_t synchronize_flags; - _filename_list_t *message_ids_to_sync; } add_files_state_t; static volatile sig_atomic_t do_print_progress = 0; @@ -443,11 +442,8 @@ add_files_recursive (notmuch_database_t *notmuch, break; /* Non-fatal issues (go on to next file) */ case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: - /* Defer sync of maildir flags until after old filenames - * are removed in the case of a rename. */ if (state->synchronize_flags == TRUE) - _filename_list_add (state->message_ids_to_sync, - notmuch_message_get_message_id (message)); + notmuch_message_maildir_flags_to_tags (message); break; case NOTMUCH_STATUS_FILE_NOT_EMAIL: fprintf (stderr, "Note: Ignoring non-mail file: %s\n", @@ -703,11 +699,16 @@ remove_filename (notmuch_database_t *notmuch, add_files_state_t *add_files_state) { notmuch_status_t status; + notmuch_message_t *message; + message = notmuch_database_find_message_by_filename (notmuch, path); status = notmuch_database_remove_message (notmuch, path); - if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) + if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) { add_files_state->renamed_messages++; - else + if (add_files_state->synchronize_flags == TRUE) + notmuch_message_maildir_flags_to_tags (message); + } else add_files_state->removed_messages++; + notmuch_message_destroy (message); return status; } @@ -782,7 +783,6 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) add_files_state.new_tags = notmuch_config_get_new_tags (config, &add_files_state.new_tags_length); add_files_state.synchronize_flags = notmuch_config_get_maildir_synchronize_flags (config); - add_files_state.message_ids_to_sync = _filename_list_create (ctx); db_path = notmuch_config_get_database_path (config); dot_notmuch_path = talloc_asprintf (ctx, "%s/%s", db_path, ".notmuch"); @@ -883,32 +883,6 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) talloc_free (add_files_state.removed_directories); talloc_free (add_files_state.directory_mtimes); - /* Now that removals are done (hence the database is aware of all - * renames), we can synchronize maildir_flags to tags for all - * messages that had new filenames appear on this run. */ - gettimeofday (&tv_start, NULL); - if (add_files_state.synchronize_flags) { - _filename_node_t *node; - notmuch_message_t *message; - for (node = add_files_state.message_ids_to_sync->head, i = 0; - node; - node = node->next, i++) - { - message = notmuch_database_find_message (notmuch, node->filename); - notmuch_message_maildir_flags_to_tags (message); - notmuch_message_destroy (message); - if (do_print_progress) { - do_print_progress = 0; - generic_print_progress ( - "Synchronized tags for", "messages", - tv_start, i, add_files_state.message_ids_to_sync->count); - } - } - } - - talloc_free (add_files_state.message_ids_to_sync); - add_files_state.message_ids_to_sync = NULL; - if (timer_is_active) stop_progress_printing_timer (); -- 1.7.5.1