changeset 19757:d7e18400a7ce

lib-storage: Avoid duplicate work when a search query has multiple header/body keys.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Tue, 16 Feb 2016 17:50:53 +0200
parents 7bad1104baf0
children 526084651206
files src/lib-storage/index/index-search.c
diffstat 1 files changed, 15 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/index-search.c	Tue Feb 16 17:48:53 2016 +0200
+++ b/src/lib-storage/index/index-search.c	Tue Feb 16 17:50:53 2016 +0200
@@ -41,6 +41,9 @@
         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 @@
 	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 @@
 		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 @@
 	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);
 	}