dovecot: Don't write fields to cache file with last_used=0. If f...

dovecot at dovecot.org dovecot at dovecot.org
Wed Nov 7 00:40:15 EET 2007


details:   http://hg.dovecot.org/dovecot/rev/02014f5b0068
changeset: 6717:02014f5b0068
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Nov 07 00:40:11 2007 +0200
description:
Don't write fields to cache file with last_used=0. If fields were just
added without being used yet, this makes sure that they're not dropped too
early by compression.

diffstat:

2 files changed, 14 insertions(+)
src/lib-index/mail-cache-compress.c |    8 ++++++++
src/lib-index/mail-cache-fields.c   |    6 ++++++

diffs (41 lines):

diff -r 35bebea1211b -r 02014f5b0068 src/lib-index/mail-cache-compress.c
--- a/src/lib-index/mail-cache-compress.c	Wed Nov 07 00:24:19 2007 +0200
+++ b/src/lib-index/mail-cache-compress.c	Wed Nov 07 00:40:11 2007 +0200
@@ -204,6 +204,14 @@ mail_cache_copy(struct mail_cache *cache
 	   used fields */
 	max_drop_time = idx_hdr->day_stamp == 0 ? 0 :
 		idx_hdr->day_stamp - MAIL_CACHE_FIELD_DROP_SECS;
+
+	/* if some fields' "last used" time is zero, they were probably just
+	   added by us. change them to the current time. */
+	for (i = 0; i < cache->fields_count; i++) {
+		if (cache->fields[i].last_used == 0)
+			cache->fields[i].last_used = ioloop_time;
+	}
+
 	orig_fields_count = cache->fields_count;
 	if (cache->file_fields_count == 0) {
 		/* creating the initial cache file. add all fields. */
diff -r 35bebea1211b -r 02014f5b0068 src/lib-index/mail-cache-fields.c
--- a/src/lib-index/mail-cache-fields.c	Wed Nov 07 00:24:19 2007 +0200
+++ b/src/lib-index/mail-cache-fields.c	Wed Nov 07 00:40:11 2007 +0200
@@ -1,6 +1,7 @@
 /* Copyright (c) 2004-2007 Dovecot authors, see the included COPYING file */
 
 #include "lib.h"
+#include "ioloop.h"
 #include "buffer.h"
 #include "hash.h"
 #include "file-cache.h"
@@ -490,6 +491,11 @@ void mail_cache_header_fields_get(struct
 	memset(&hdr, 0, sizeof(hdr));
 	hdr.fields_count = cache->file_fields_count;
 	for (i = 0; i < cache->fields_count; i++) {
+		if (cache->fields[i].last_used == 0) {
+			/* return newly added fields' last_used as
+			   the current time */
+			cache->fields[i].last_used = ioloop_time;
+		}
 		if (CACHE_FIELD_IS_NEWLY_WANTED(cache, i))
 			hdr.fields_count++;
 	}


More information about the dovecot-cvs mailing list