]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Avoid duplicate work when a search query has multiple header/body keys.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 16 Feb 2016 15:50:53 +0000 (17:50 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 16 Feb 2016 15:54:49 +0000 (17:54 +0200)
src/lib-storage/index/index-search.c

index 18011d3111b7e745152983bcaaef650b67e11e15..365b2c39d99e303ad0cbfa819d1149c6699ad88b 100644 (file)
@@ -41,6 +41,9 @@ struct search_header_context {
         struct index_mail *imail;
        struct mail_search_arg *args;
 
+       struct message_block decoded_block;
+       bool decoded_block_set;
+
         struct message_header_line *hdr;
 
        unsigned int parse_headers:1;
@@ -525,7 +528,7 @@ static void search_header_arg(struct mail_search_arg *arg,
        if (msg_search_ctx == NULL)
                return;
 
-       T_BEGIN {
+       if (!ctx->decoded_block_set) { T_BEGIN {
                struct message_address *addr;
                string_t *str;
 
@@ -554,8 +557,16 @@ static void search_header_arg(struct mail_search_arg *arg,
                default:
                        i_unreached();
                }
-               ret = message_search_more(msg_search_ctx, &block) ? 1 : 0;
-       } T_END;
+               ret = message_search_more_get_decoded(msg_search_ctx, &block,
+                                                     &ctx->decoded_block) ? 1 : 0;
+               ctx->decoded_block_set = TRUE;
+       } T_END; } else {
+               /* this block was already decoded and saved by an earlier
+                  search arg. use the already-decoded block to avoid
+                  duplicating work. */
+               ret = message_search_more_decoded(msg_search_ctx,
+                                                 &ctx->decoded_block) ? 1 : 0;
+       }
 
        /* there may be multiple headers. don't mark this failed yet. */
        if (ret > 0)
@@ -607,6 +618,7 @@ static void search_header(struct message_header_line *hdr,
        if (ctx->custom_header || strcasecmp(hdr->name, "Date") == 0) {
                ctx->hdr = hdr;
 
+               ctx->decoded_block_set = FALSE;
                ctx->custom_header = FALSE;
                (void)mail_search_args_foreach(ctx->args, search_header_arg, ctx);
        }