]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Avoid unnecessary UIDNEXT lookups after saving a mail
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 5 May 2017 12:20:05 +0000 (15:20 +0300)
committerGitLab <gitlab@git.dovecot.net>
Fri, 12 May 2017 18:50:32 +0000 (21:50 +0300)
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.

src/lib-storage/index/index-mailbox-size.c

index 9d2f326a1b38ae1bae1c71740b8a0583bf714595..85211584ab23f1f2116b45fd2d0183e17517de32 100644 (file)
@@ -467,12 +467,17 @@ void index_mailbox_vsize_update_appends(struct mailbox *box)
 
        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);
 }