Skip to content

Commit

Permalink
lib-storage: Avoid duplicate work when a search query has multiple he…
Browse files Browse the repository at this point in the history
…ader/body keys.
  • Loading branch information
sirainen committed Feb 16, 2016
1 parent 121f820 commit 7fbc81a
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/lib-storage/index/index-search.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 7fbc81a

Please sign in to comment.