dovecot-1.2: Don't cache Date: header if we don't really want it.

dovecot at dovecot.org dovecot at dovecot.org
Mon Mar 23 23:41:23 EET 2009


details:   http://hg.dovecot.org/dovecot-1.2/rev/c01259945820
changeset: 8849:c01259945820
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Mar 23 17:40:32 2009 -0400
description:
Don't cache Date: header if we don't really want it.

diffstat:

3 files changed, 32 insertions(+), 12 deletions(-)
src/lib-storage/index/index-mail-headers.c |   39 ++++++++++++++++++++--------
src/lib-storage/index/index-mail.c         |    4 ++
src/lib-storage/index/index-mail.h         |    1 

diffs (114 lines):

diff -r dd441977c578 -r c01259945820 src/lib-storage/index/index-mail-headers.c
--- 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 @@ static void index_mail_parse_header_fini
 			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 @@ void index_mail_parse_header_init(struct
 {
 	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 @@ void index_mail_parse_header_init(struct
 		}
 	}
 
-	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 @@ index_mail_get_raw_headers(struct index_
 
 	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,
diff -r dd441977c578 -r c01259945820 src/lib-storage/index/index-mail.c
--- 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 @@ void index_mail_cache_add_idx(struct ind
 			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 @@ static void index_mail_reset(struct inde
 	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;
diff -r dd441977c578 -r c01259945820 src/lib-storage/index/index-mail.h
--- 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 @@ struct index_mail_data {
 	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;


More information about the dovecot-cvs mailing list