]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Optimize behavior when building THREAD tree with empty cache
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 19 Apr 2021 16:48:09 +0000 (18:48 +0200)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Fri, 26 Nov 2021 10:59:20 +0000 (10:59 +0000)
Although it's possible that Date, Subject or received-date isn't actually
needed for all mails, it's much more efficient behavior to add all of these
to cache at the same time if they're not there already. Otherwise the same
mail could be opened and parsed up to 3 times.

src/lib-storage/index/index-thread.c

index 8c0812c16f5f2437f4fa23e1b3815a44fbb8439f..2b1ba045ac73f78e52440b5ce5ed9e3c2e7c0b43 100644 (file)
@@ -296,7 +296,7 @@ mail_thread_map_add_mail(struct mail_thread_context *ctx, struct mail *mail)
 static int mail_thread_index_map_build(struct mail_thread_context *ctx)
 {
        static const char *wanted_headers[] = {
-               HDR_MESSAGE_ID, HDR_IN_REPLY_TO, HDR_REFERENCES,
+               HDR_MESSAGE_ID, HDR_IN_REPLY_TO, HDR_REFERENCES, HDR_SUBJECT,
                NULL
        };
        struct mail_thread_mailbox *tbox = MAIL_THREAD_CONTEXT_REQUIRE(ctx->box);
@@ -320,7 +320,8 @@ static int mail_thread_index_map_build(struct mail_thread_context *ctx)
        }
 
        headers_ctx = mailbox_header_lookup_init(ctx->box, wanted_headers);
-       ctx->tmp_mail = mail_alloc(ctx->t, 0, headers_ctx);
+       ctx->tmp_mail = mail_alloc(ctx->t, MAIL_FETCH_DATE |
+                                  MAIL_FETCH_RECEIVED_DATE, headers_ctx);
 
        /* add all missing UIDs */
        ctx->strmap_sync = mail_index_strmap_view_sync_init(tbox->strmap_view,
@@ -337,7 +338,9 @@ static int mail_thread_index_map_build(struct mail_thread_context *ctx)
        search_args = mail_search_build_init();
        mail_search_build_add_seqset(search_args, seq1, seq2);
        search_ctx = mailbox_search_init(ctx->t, search_args, NULL,
-                                        0, headers_ctx);
+                                        MAIL_FETCH_DATE |
+                                        MAIL_FETCH_RECEIVED_DATE,
+                                        headers_ctx);
        mailbox_header_lookup_unref(&headers_ctx);
        mail_search_args_unref(&search_args);