Mercurial > dovecot > original-hg > dovecot-1.2
changeset 8849:c01259945820 HEAD
Don't cache Date: header if we don't really want it.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 23 Mar 2009 17:40:32 -0400 |
parents | dd441977c578 |
children | 79311c07f98f |
files | src/lib-storage/index/index-mail-headers.c src/lib-storage/index/index-mail.c src/lib-storage/index/index-mail.h |
diffstat | 3 files changed, 32 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/index-mail-headers.c Mon Mar 23 16:33:11 2009 -0400 +++ b/src/lib-storage/index/index-mail-headers.c Mon Mar 23 17:40:32 2009 -0400 @@ -142,16 +142,20 @@ index_mail_cache_add_idx(mail, match_idx, NULL, 0); } } + + mail->data.dont_cache_field_idx = -1UL; } static unsigned int -get_header_field_idx(struct index_mailbox *ibox, const char *field) +get_header_field_idx(struct index_mailbox *ibox, const char *field, + enum mail_cache_decision_type decision) { struct mail_cache_field header_field = { NULL, 0, MAIL_CACHE_FIELD_HEADER, 0, - MAIL_CACHE_DECISION_TEMP + MAIL_CACHE_DECISION_NO }; + header_field.decision = decision; T_BEGIN { header_field.name = t_strconcat("hdr.", field, NULL); mail_cache_register_fields(ibox->cache, &header_field, 1); @@ -196,7 +200,8 @@ { struct index_header_lookup_ctx *headers = (struct index_header_lookup_ctx *)_headers; - unsigned int i; + const uint8_t *match; + unsigned int i, field_idx, match_count; mail->header_seq = mail->data.seq; if (mail->header_data == NULL) { @@ -235,17 +240,28 @@ } } - if ((mail->data.cache_fetch_fields & MAIL_FETCH_DATE) != 0 || - mail->data.save_sent_date) { - array_idx_set(&mail->header_match, - get_header_field_idx(mail->ibox, "Date"), - &mail->header_match_value); - } - /* register also all the other headers that exist in cache file */ T_BEGIN { index_mail_parse_header_register_all_wanted(mail); } T_END; + + /* if we want sent date, it doesn't mean that we also want to cache + Date: header. if we have Date field's index set at this point we + know that we want it. otherwise add it and remember that we don't + want it cached. */ + field_idx = get_header_field_idx(mail->ibox, "Date", + MAIL_CACHE_DECISION_NO); + match = array_get(&mail->header_match, &match_count); + if (field_idx < match_count && + match[field_idx] == mail->header_match_value) { + /* cache Date: header */ + } else if ((mail->data.cache_fetch_fields & MAIL_FETCH_DATE) != 0 || + mail->data.save_sent_date) { + /* parse Date: header, but don't cache it. */ + mail->data.dont_cache_field_idx = field_idx; + array_idx_set(&mail->header_match, field_idx, + &mail->header_match_value); + } } static void index_mail_parse_finish_imap_envelope(struct index_mail *mail) @@ -591,7 +607,8 @@ i_assert(field != NULL); - field_idx = get_header_field_idx(mail->ibox, field); + field_idx = get_header_field_idx(mail->ibox, field, + MAIL_CACHE_DECISION_TEMP); dest = str_new(mail->data_pool, 128); if (mail_cache_lookup_headers(mail->trans->cache_view, dest,
--- a/src/lib-storage/index/index-mail.c Mon Mar 23 16:33:11 2009 -0400 +++ b/src/lib-storage/index/index-mail.c Mon Mar 23 17:40:32 2009 -0400 @@ -428,7 +428,8 @@ return; } - if (!mail->data.no_caching) { + if (!mail->data.no_caching && + mail->data.dont_cache_field_idx != field_idx) { mail_cache_add(mail->trans->cache_trans, mail->data.seq, field_idx, data, data_size); } @@ -1138,6 +1139,7 @@ data->save_date = (time_t)-1; data->received_date = (time_t)-1; data->sent_date.time = (uint32_t)-1; + data->dont_cache_field_idx = -1UL; mail->mail.mail.seq = 0; mail->mail.mail.uid = 0;
--- a/src/lib-storage/index/index-mail.h Mon Mar 23 16:33:11 2009 -0400 +++ b/src/lib-storage/index/index-mail.h Mon Mar 23 17:40:32 2009 -0400 @@ -86,6 +86,7 @@ enum index_mail_access_part access_part; /* dont_cache_fields overrides cache_fields */ enum mail_fetch_field cache_fetch_fields, dont_cache_fetch_fields; + unsigned int dont_cache_field_idx; struct istream *stream, *filter_stream; struct message_size hdr_size, body_size;