]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Don't fetch wanted_fields for messages that don't match the search query.
authorTimo Sirainen <tss@iki.fi>
Tue, 25 Nov 2014 00:56:37 +0000 (02:56 +0200)
committerTimo Sirainen <tss@iki.fi>
Tue, 25 Nov 2014 00:56:37 +0000 (02:56 +0200)
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.

src/lib-storage/index/index-mail.c
src/lib-storage/index/index-mail.h
src/lib-storage/index/index-search.c

index bf06d93ee06e4a379d492752d9e8f725bf3d6857..431584a1f746c1468500250f27501a80da58d346 100644 (file)
@@ -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)
index 298a46d1a2bb9e51b6db58b9225f1a753a2853b6..a2f535b7ab8bd147c1b94a9bb8e9ec3f909650ab 100644 (file)
@@ -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);
index 3b5ce2d6e0d44ebd46ee1f7b9d7b765d75601bba..18f0e5faaada011a5ab482eca440e335866a739e 100644 (file)
@@ -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;
 }