From: Timo Sirainen Date: Fri, 5 May 2017 12:20:05 +0000 (+0300) Subject: lib-storage: Avoid unnecessary UIDNEXT lookups after saving a mail X-Git-Tag: 2.3.0.rc1~1632 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b45d816c73e0bfba55d84fb50005ba2714ac0fa;p=thirdparty%2Fdovecot%2Fcore.git 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. --- diff --git a/src/lib-storage/index/index-mailbox-size.c b/src/lib-storage/index/index-mailbox-size.c index 9d2f326a1b..85211584ab 100644 --- a/src/lib-storage/index/index-mailbox-size.c +++ b/src/lib-storage/index/index-mailbox-size.c @@ -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); }