From: Timo Sirainen Date: Tue, 25 Nov 2014 00:56:37 +0000 (+0200) Subject: lib-storage: Don't fetch wanted_fields for messages that don't match the search query. X-Git-Tag: 2.2.16.rc1~200 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=96a410ecef6d2e08c8bce325eec084ce1edce100;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Don't fetch wanted_fields for messages that don't match the search query. For example "doveadm fetch text subject foo" was opening all the mails, even though only a few matched the subject (that was hopefully already in cache file). The behavior still isn't perfect though. The wanted_fields should probably be split into search_wanted_fields and fetch_wanted_fields, but the current behavior is likely good enough for now. --- diff --git a/src/lib-storage/index/index-mail.c b/src/lib-storage/index/index-mail.c index bf06d93ee0..431584a1f7 100644 --- a/src/lib-storage/index/index-mail.c +++ b/src/lib-storage/index/index-mail.c @@ -1435,9 +1435,9 @@ static void check_envelope(struct index_mail *mail) mail->data.save_envelope = TRUE; } -static void index_mail_update_access_parts(struct index_mail *mail) +void index_mail_update_access_parts(struct mail *_mail) { - struct mail *_mail = &mail->mail.mail; + struct index_mail *mail = (struct index_mail *)_mail; struct index_mail_data *data = &mail->data; const struct mail_cache_field *cache_fields = mail->ibox->cache_fields; struct mail_cache_view *cache_view = _mail->transaction->cache_view; @@ -1569,7 +1569,12 @@ void index_mail_set_seq(struct mail *_mail, uint32_t seq, bool saving) return; } - index_mail_update_access_parts(mail); + if (!mail->search_mail) + index_mail_update_access_parts(_mail); + else { + /* searching code will call the index_mail_update_access_parts() + after we know the mail is actually wanted to be fetched. */ + } mail->data.initialized = TRUE; } @@ -1660,7 +1665,7 @@ void index_mail_add_temp_wanted_fields(struct mail *_mail, mailbox_header_lookup_init(_mail->box, array_idx(&names, 0)); } - index_mail_update_access_parts(mail); + index_mail_update_access_parts(_mail); } void index_mail_set_uid_cache_updates(struct mail *_mail, bool set) diff --git a/src/lib-storage/index/index-mail.h b/src/lib-storage/index/index-mail.h index 298a46d1a2..a2f535b7ab 100644 --- a/src/lib-storage/index/index-mail.h +++ b/src/lib-storage/index/index-mail.h @@ -171,6 +171,7 @@ bool index_mail_prefetch(struct mail *mail); void index_mail_add_temp_wanted_fields(struct mail *mail, enum mail_fetch_field fields, struct mailbox_header_lookup_ctx *headers); +void index_mail_update_access_parts(struct mail *mail); void index_mail_close(struct mail *mail); void index_mail_close_streams(struct index_mail *mail); void index_mail_free(struct mail *mail); diff --git a/src/lib-storage/index/index-search.c b/src/lib-storage/index/index-search.c index 3b5ce2d6e0..18f0e5faaa 100644 --- a/src/lib-storage/index/index-search.c +++ b/src/lib-storage/index/index-search.c @@ -1550,6 +1550,13 @@ static int search_more_with_mail(struct index_search_context *ctx, mail_search_args_reset(_ctx->args->args, FALSE); if (match != 0) { + /* either matched or result is still unknown. + anyway we're far enough now that we probably want + to update the access_parts. the only problem here is + if searching would want fewer access_parts than the + fetching part, but that's probably not a big problem + usually. */ + index_mail_update_access_parts(mail); ret = 1; break; } @@ -1730,6 +1737,7 @@ bool index_storage_search_next_nonblock(struct mail_search_context *_ctx, mailp = array_idx(&ctx->mails, 0); mail_set_seq(*mailp, seq); + index_mail_update_access_parts(*mailp); *mail_r = *mailp; return TRUE; }