Wouldn't this be simpler and more general?<div><br></div><div><div><div>--- a/notmuch-new.c</div><div>+++ b/notmuch-new.c</div><div>@@ -419,12 +419,11 @@ add_files_recursive (notmuch_database_t *notmuch,</div><div> case NOTMUCH_STATUS_SUCCESS:</div>
<div> state->added_messages++;</div><div> for (tag=state->new_tags; *tag != NULL; tag++)</div><div> notmuch_message_add_tag (message, *tag);</div><div> /* Defer sync of maildir flags until after old filenames</div>
<div> * are removed in the case of a rename. */</div><div> if (state->synchronize_flags == TRUE)</div><div>- _filename_list_add (state->message_ids_to_sync,</div><div>- notmuch_message_get_message_id (message));</div>
<div>+ notmuch_message_maildir_flags_to_tags (message);</div><div> break;</div><div> /* Non-fatal issues (go on to next file) */</div><div> case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:</div>
<div><br></div></div><div>The idea is that, if notmuch_database_add_message returns NOTMUCH_STATUS_SUCCESS, then we know this is a new message (and not a rename or anything complicated) and thus might as well perform the flag synchronization immediately. If it returns NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID, then it could be a rename (or something more complicated), and so we defer the flag synchronization like usual. This works for any new messages, regardless of whether this is the initial import or not.</div>
<div><br></div><div>I believe my reasoning is correct. At least, it passes the maildir sync test cases, so if it isn't correct, then we need more maildir sync tests.</div><meta http-equiv="content-type" content="text/html; charset=utf-8"><div>
<br></div><div class="gmail_quote">On Fri, Jan 21, 2011 at 4:59 AM, Michal Sojka <span dir="ltr"><<a href="mailto:sojkam1@fel.cvut.cz">sojkam1@fel.cvut.cz</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
When notmuch new is run for the first time, it is not necessary to defer<br>
maildir flags synchronization to later because we already know that no<br>
files will be removed.<br>
<br>
Performing the maildinr flag synchronization immediately after the<br>
message is added to the database has the advantage that the message is<br>
likely hot in the disk cache so the synchronization is faster.<br>
Additionally, we also save one database query for each message, which<br>
must be performed when the operation is deferred.<br>
<br>
Without this patchi, the first notmuch new of 200k messages (3 GB) took<br>
1h and 46m out of which 20m was maildir flags synchronization. With this<br>
patch, the whole operation took only 1h and 36m.<br>
---<br>
notmuch-new.c | 36 ++++++++++++++++++++++++++----------<br>
1 files changed, 26 insertions(+), 10 deletions(-)<br>
<br>
diff --git a/notmuch-new.c b/notmuch-new.c<br>
index cdf8513..a2af045 100644<br>
--- a/notmuch-new.c<br>
+++ b/notmuch-new.c<br>
@@ -420,19 +420,35 @@ add_files_recursive (notmuch_database_t *notmuch,<br>
state->added_messages++;<br>
for (tag=state->new_tags; *tag != NULL; tag++)<br>
notmuch_message_add_tag (message, *tag);<br>
- /* Defer sync of maildir flags until after old filenames<br>
- * are removed in the case of a rename. */<br>
- if (state->synchronize_flags == TRUE)<br>
- _filename_list_add (state->message_ids_to_sync,<br>
- notmuch_message_get_message_id (message));<br>
+ if (state->synchronize_flags == TRUE) {<br>
+ if (!state->total_files) {<br>
+ /* Defer sync of maildir flags until after old filenames<br>
+ * are removed in the case of a rename. */<br>
+ _filename_list_add (state->message_ids_to_sync,<br>
+ notmuch_message_get_message_id (message));<br>
+ } else {<br>
+ /* During the first notmuch new we synchronize<br>
+ * flags immediately, while the message is hot in<br>
+ * disk cache. */<br>
+ notmuch_message_maildir_flags_to_tags (message);<br>
+ }<br>
+ }<br>
break;<br>
/* Non-fatal issues (go on to next file) */<br>
case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:<br>
- /* Defer sync of maildir flags until after old filenames<br>
- * are removed in the case of a rename. */<br>
- if (state->synchronize_flags == TRUE)<br>
- _filename_list_add (state->message_ids_to_sync,<br>
- notmuch_message_get_message_id (message));<br>
+ if (state->synchronize_flags == TRUE) {<br>
+ if (!state->total_files) {<br>
+ /* Defer sync of maildir flags until after old filenames<br>
+ * are removed in the case of a rename. */<br>
+ _filename_list_add (state->message_ids_to_sync,<br>
+ notmuch_message_get_message_id (message));<br>
+ } else {<br>
+ /* During the first notmuch new we synchronize<br>
+ * flags immediately, while the message is hot in<br>
+ * disk cache. */<br>
+ notmuch_message_maildir_flags_to_tags (message);<br>
+ }<br>
+ }<br>
break;<br>
case NOTMUCH_STATUS_FILE_NOT_EMAIL:<br>
fprintf (stderr, "Note: Ignoring non-mail file: %s\n",<br>
<font color="#888888">--<br>
1.7.2.3<br>
<br>
_______________________________________________<br>
notmuch mailing list<br>
<a href="mailto:notmuch@notmuchmail.org">notmuch@notmuchmail.org</a><br>
<a href="http://notmuchmail.org/mailman/listinfo/notmuch" target="_blank">http://notmuchmail.org/mailman/listinfo/notmuch</a><br>
</font></blockquote></div><br></div>