]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
indexer: cmd_index_box_precache() - Avoid opening the mailbox when unnecessary
authorMarco Bettini <marco.bettini@open-xchange.com>
Mon, 31 Jul 2023 15:55:12 +0000 (15:55 +0000)
committerMarco Bettini <marco.bettini@open-xchange.com>
Tue, 10 Oct 2023 08:04:41 +0000 (08:04 +0000)
src/doveadm/doveadm-mail-index.c

index 42446f59d2c148ee22beaf8712744f7c94d47d03..dd75e04c9601205515df1b532f8ce36f3c827266 100644 (file)
@@ -41,16 +41,23 @@ static int cmd_index_box_precache(struct doveadm_mail_cmd_context *dctx,
        unsigned int counter = 0, max;
        int ret = 0;
 
-       if (mailbox_get_metadata(box, MAILBOX_METADATA_PRECACHE_FIELDS,
-                                &metadata) < 0) {
-               e_error(event, "Mailbox %s: Precache-fields lookup failed: %s",
+       if (mailbox_get_status(box, STATUS_MESSAGES | STATUS_FTS_LAST_INDEXED_UID,
+                              &status) < 0) {
+               e_error(event, "Mailbox %s: Status lookup failed: %s",
                        mailbox_get_vname(box),
                        mailbox_get_last_internal_error(box, NULL));
                return -1;
        }
-       if (mailbox_get_status(box, STATUS_MESSAGES | STATUS_FTS_LAST_INDEXED_UID,
-                              &status) < 0) {
-               e_error(event, "Mailbox %s: Status lookup failed: %s",
+
+       if (status.fts_last_indexed_uid >= status.uidnext - 1) {
+               e_info(event, "Mailbox %s: Index is already up to date",
+                      mailbox_get_vname(box));
+               return 0;
+       }
+
+       if (mailbox_get_metadata(box, MAILBOX_METADATA_PRECACHE_FIELDS,
+                                &metadata) < 0) {
+               e_error(event, "Mailbox %s: Precache-fields lookup failed: %s",
                        mailbox_get_vname(box),
                        mailbox_get_last_internal_error(box, NULL));
                return -1;
@@ -62,13 +69,6 @@ static int cmd_index_box_precache(struct doveadm_mail_cmd_context *dctx,
                                      &unused, &seq);
        seq++;
 
-       if (seq > status.messages) {
-               if (doveadm_verbose) {
-                       e_info(event, "%s: Cache is already up to date",
-                              mailbox_get_vname(box));
-               }
-               return 0;
-       }
        if (doveadm_verbose) {
                e_info(event, "%s: Caching mails seq=%u..%u",
                       mailbox_get_vname(box), seq, status.messages);