changeset 22040:99752d3e656b

lib-storage: Avoid unnecessary UIDNEXT lookups after saving a mail The vsize checking code was expecting that this would always be a cheap operation, but with imapc code it could trigger a remote STATUS (UIDNEXT) call. Do this only when we've checked that this mailbox is updating vsize header at all.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Fri, 05 May 2017 15:20:05 +0300
parents cd2b83cf966e
children 21fab4826117
files src/lib-storage/index/index-mailbox-size.c
diffstat 1 files changed, 10 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/index-mailbox-size.c	Fri May 12 15:42:31 2017 +0300
+++ b/src/lib-storage/index/index-mailbox-size.c	Fri May 05 15:20:05 2017 +0300
@@ -467,12 +467,17 @@
 
 	update = index_mailbox_vsize_update_init(box);
 
-	mailbox_get_open_status(update->box, STATUS_UIDNEXT, &status);
 	/* update here only if we don't need to rebuild the whole vsize. */
 	index_mailbox_vsize_check_rebuild(update);
-	if (update->vsize_hdr.highest_uid + 1 != status.uidnext &&
-	    index_mailbox_vsize_want_updates(update) &&
-	    index_mailbox_vsize_update_try_lock(update))
-		(void)index_mailbox_vsize_hdr_add_missing(update, FALSE);
+	if (index_mailbox_vsize_want_updates(update)) {
+		/* Get the UIDNEXT only after checking that vsize updating is
+		   even potentially wanted for this mailbox. We especially
+		   don't want to do this with imapc, because it could trigger
+		   a remote STATUS (UIDNEXT) call. */
+		mailbox_get_open_status(update->box, STATUS_UIDNEXT, &status);
+		if (update->vsize_hdr.highest_uid + 1 != status.uidnext &&
+		    index_mailbox_vsize_update_try_lock(update))
+			(void)index_mailbox_vsize_hdr_add_missing(update, FALSE);
+	}
 	index_mailbox_vsize_update_deinit(&update);
 }