changeset 6841:0c970b3493ac HEAD

mail_cache_field_want_add(): Return TRUE for temp fields only if we're adding the field to a new enough message.
author Timo Sirainen <tss@iki.fi>
date Thu, 22 Nov 2007 07:56:38 +0200
parents efec8836586a
children d2c8269a0679
files src/lib-index/mail-cache-compress.c src/lib-index/mail-cache-private.h src/lib-index/mail-cache-transaction.c src/lib-index/mail-cache.c
diffstat 4 files changed, 42 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-cache-compress.c	Thu Nov 22 07:46:25 2007 +0200
+++ b/src/lib-index/mail-cache-compress.c	Thu Nov 22 07:56:38 2007 +0200
@@ -167,21 +167,6 @@
 	time_t max_drop_time;
 
 	view = mail_index_transaction_get_view(trans);
-
-	/* get sequence of first message which doesn't need its temp fields
-	   removed. */
-	idx_hdr = mail_index_get_header(view);
-	if (idx_hdr->day_first_uid[7] == 0) {
-		first_new_seq = 1;
-		message_count = mail_index_view_get_messages_count(view);
-	} else {
-		if (!mail_index_lookup_seq_range(view,
-						 idx_hdr->day_first_uid[7],
-						 (uint32_t)-1, &first_new_seq,
-						 &message_count))
-			first_new_seq = message_count+1;
-	}
-
 	cache_view = mail_cache_view_open(cache, view);
 	output = o_stream_create_fd_file(fd, 0, FALSE);
 
@@ -202,6 +187,7 @@
 
 	/* @UNSAFE: drop unused fields and create a field mapping for
 	   used fields */
+	idx_hdr = mail_index_get_header(view);
 	max_drop_time = idx_hdr->day_stamp == 0 ? 0 :
 		idx_hdr->day_stamp - MAIL_CACHE_FIELD_DROP_SECS;
 
@@ -228,6 +214,11 @@
 		}
 	}
 
+	/* get sequence of first message which doesn't need its temp fields
+	   removed. */
+	first_new_seq = mail_cache_get_first_new_seq(view);
+	message_count = mail_index_view_get_messages_count(view);
+
 	i_array_init(ext_offsets, message_count);
 	for (seq = 1; seq <= message_count; seq++) {
 		if (mail_index_transaction_is_expunged(trans, seq)) {
--- a/src/lib-index/mail-cache-private.h	Thu Nov 22 07:46:25 2007 +0200
+++ b/src/lib-index/mail-cache-private.h	Thu Nov 22 07:56:38 2007 +0200
@@ -231,6 +231,7 @@
 
 int mail_cache_get_record(struct mail_cache *cache, uint32_t offset,
 			  const struct mail_cache_record **rec_r);
+uint32_t mail_cache_get_first_new_seq(struct mail_index_view *view);
 
 /* Returns TRUE if offset is already in given array. Otherwise return FALSE
    and add the offset to the array. */
--- a/src/lib-index/mail-cache-transaction.c	Thu Nov 22 07:46:25 2007 +0200
+++ b/src/lib-index/mail-cache-transaction.c	Thu Nov 22 07:56:38 2007 +0200
@@ -27,6 +27,7 @@
 	struct mail_index_transaction *trans;
 
 	uint32_t cache_file_seq;
+	uint32_t first_new_seq;
 
 	buffer_t *cache_data;
 	ARRAY_DEFINE(cache_data_seq, uint32_t);
@@ -965,8 +966,23 @@
 	mail_cache_transaction_open_if_needed(ctx);
 
 	decision = mail_cache_field_get_decision(ctx->view->cache, field_idx);
-	if ((decision & ~MAIL_CACHE_DECISION_FORCED) == MAIL_CACHE_DECISION_NO)
+	decision &= ~MAIL_CACHE_DECISION_FORCED;
+	switch (decision) {
+	case MAIL_CACHE_DECISION_NO:
 		return FALSE;
+	case MAIL_CACHE_DECISION_TEMP:
+		/* add it only if it's newer than what we would drop when
+		   compressing */
+		if (ctx->first_new_seq == 0) {
+			ctx->first_new_seq =
+				mail_cache_get_first_new_seq(ctx->view->view);
+		}
+		if (seq < ctx->first_new_seq)
+			return FALSE;
+		break;
+	default:
+		break;
+	}
 
 	return mail_cache_field_exists(ctx->view, seq, field_idx) == 0;
 }
--- a/src/lib-index/mail-cache.c	Thu Nov 22 07:46:25 2007 +0200
+++ b/src/lib-index/mail-cache.c	Thu Nov 22 07:56:38 2007 +0200
@@ -669,3 +669,21 @@
 	buffer_free(&view->cached_exists_buf);
 	i_free(view);
 }
+
+uint32_t mail_cache_get_first_new_seq(struct mail_index_view *view)
+{
+	const struct mail_index_header *idx_hdr;
+	uint32_t first_new_seq, message_count;
+
+	idx_hdr = mail_index_get_header(view);
+	if (idx_hdr->day_first_uid[7] == 0)
+		return 1;
+
+	if (!mail_index_lookup_seq_range(view, idx_hdr->day_first_uid[7],
+					 (uint32_t)-1, &first_new_seq,
+					 &message_count)) {
+		/* all messages are too old */
+		return message_count+1;
+	}
+	return first_new_seq;
+}