dovecot: When adding new fields to the cache file, add all the f...

dovecot at dovecot.org dovecot at dovecot.org
Mon Nov 5 21:38:25 EET 2007


details:   http://hg.dovecot.org/dovecot/rev/68adf46a6b3f
changeset: 6696:68adf46a6b3f
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Nov 05 21:38:20 2007 +0200
description:
When adding new fields to the cache file, add all the fields we currently
know about to avoid adding them one-by-one.

diffstat:

2 files changed, 27 insertions(+), 12 deletions(-)
src/lib-index/mail-cache-compress.c    |   19 +++++++++++++------
src/lib-index/mail-cache-transaction.c |   20 ++++++++++++++------

diffs (82 lines):

diff -r 76c0e3a4df7a -r 68adf46a6b3f src/lib-index/mail-cache-compress.c
--- a/src/lib-index/mail-cache-compress.c	Mon Nov 05 21:37:27 2007 +0200
+++ b/src/lib-index/mail-cache-compress.c	Mon Nov 05 21:38:20 2007 +0200
@@ -205,12 +205,19 @@ mail_cache_copy(struct mail_cache *cache
 	max_drop_time = idx_hdr->day_stamp == 0 ? 0 :
 		idx_hdr->day_stamp - MAIL_CACHE_FIELD_DROP_SECS;
 	orig_fields_count = cache->fields_count;
-	for (i = used_fields_count = 0; i < orig_fields_count; i++) {
-		if (cache->fields[i].last_used < max_drop_time)
-			cache->fields[i].used = FALSE;
-
-		ctx.field_file_map[i] = !cache->fields[i].used ? (uint32_t)-1 :
-			used_fields_count++;
+	if (cache->file_fields_count == 0) {
+		/* creating the initial cache file. add all fields. */
+		for (i = 0; i < orig_fields_count; i++)
+			ctx.field_file_map[i] = i;
+		used_fields_count = i;
+	} else {
+		for (i = used_fields_count = 0; i < orig_fields_count; i++) {
+			if (cache->fields[i].last_used < max_drop_time)
+				cache->fields[i].used = FALSE;
+
+			ctx.field_file_map[i] = !cache->fields[i].used ?
+				(uint32_t)-1 : used_fields_count++;
+		}
 	}
 
 	i_array_init(ext_offsets, message_count);
diff -r 76c0e3a4df7a -r 68adf46a6b3f src/lib-index/mail-cache-transaction.c
--- a/src/lib-index/mail-cache-transaction.c	Mon Nov 05 21:37:27 2007 +0200
+++ b/src/lib-index/mail-cache-transaction.c	Mon Nov 05 21:38:20 2007 +0200
@@ -713,8 +713,15 @@ static int mail_cache_header_add_field(s
 				       unsigned int field_idx)
 {
 	struct mail_cache *cache = ctx->cache;
+	unsigned int i;
 	buffer_t *buffer;
 	int ret;
+
+	/* we want to avoid adding all the fields one by one to the cache file,
+	   so just add all of them at once in here. the unused ones get dropped
+	   later when compressing. */
+	for (i = 0; i < cache->fields_count; i++)
+		cache->fields[i].used = TRUE;
 
 	if ((ret = mail_cache_transaction_lock(ctx)) <= 0) {
 		/* create the cache file if it doesn't exist yet */
@@ -724,8 +731,10 @@ static int mail_cache_header_add_field(s
 
 		if (mail_cache_compress(cache, ctx->trans) < 0)
 			return -1;
-		if ((ret = mail_cache_transaction_lock(ctx)) <= 0)
-			return -1;
+
+		/* compression should have added it */
+		i_assert(cache->field_file_map[field_idx] != (uint32_t)-1);
+		return 0;
 	}
 
 	/* re-read header to make sure we don't lose any fields. */
@@ -733,10 +742,6 @@ static int mail_cache_header_add_field(s
 		(void)mail_cache_unlock(cache);
 		return -1;
 	}
-
-	/* update these only after reading */
-	cache->fields[field_idx].last_used = ioloop_time;
-	cache->fields[field_idx].used = TRUE;
 
 	if (cache->field_file_map[field_idx] != (uint32_t)-1) {
 		/* it was already added */
@@ -795,6 +800,9 @@ void mail_cache_add(struct mail_cache_tr
 		/* we'll have to add this field to headers */
 		if (mail_cache_header_add_field(ctx, field_idx) < 0)
 			return;
+
+		if (ctx->cache_file_seq == 0)
+			ctx->cache_file_seq = ctx->cache->hdr->file_seq;
 
 		file_field = ctx->cache->field_file_map[field_idx];
 		i_assert(file_field != (uint32_t)-1);


More information about the dovecot-cvs mailing list