From: Timo Sirainen Date: Tue, 16 Feb 2016 15:50:53 +0000 (+0200) Subject: lib-storage: Avoid duplicate work when a search query has multiple header/body keys. X-Git-Tag: 2.2.22.rc1~163 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7fbc81a103d10f180d079cf4c14c353cb28a2e77;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Avoid duplicate work when a search query has multiple header/body keys. --- diff --git a/src/lib-storage/index/index-search.c b/src/lib-storage/index/index-search.c index 18011d3111..365b2c39d9 100644 --- a/src/lib-storage/index/index-search.c +++ b/src/lib-storage/index/index-search.c @@ -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); }