changeset 7569:ea913434d522 HEAD

Sort index optimization: Don't write changes to sort IDs if we're doing it only to give sort ID space to expunged messages.
author Timo Sirainen <tss@iki.fi>
date Thu, 29 May 2008 18:49:55 +0300
parents 66e6b61680a5
children 2220b2aa9f7c
files src/lib-storage/index/index-sort-string.c
diffstat 1 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/index-sort-string.c	Thu May 29 18:47:46 2008 +0300
+++ b/src/lib-storage/index/index-sort-string.c	Thu May 29 18:49:55 2008 +0300
@@ -34,6 +34,7 @@
 	unsigned int first_missing_sort_id_idx;
 
 	uint32_t ext_id, last_seq, highest_reset_id;
+	uint32_t lowest_nonexpunged_zero;
 
 	unsigned int regetting:1;
 	unsigned int have_all_wanted:1;
@@ -157,6 +158,14 @@
 		node->sort_id = 0;
 	} else {
 		node->sort_id = data == NULL ? 0 : *(const uint32_t *)data;
+		if (node->sort_id == 0) {
+			if (ctx->lowest_nonexpunged_zero > node->seq ||
+			    ctx->lowest_nonexpunged_zero == 0)
+				ctx->lowest_nonexpunged_zero = node->seq;
+		} else {
+			i_assert(ctx->lowest_nonexpunged_zero == 0 ||
+				 ctx->lowest_nonexpunged_zero > node->seq);
+		}
 	}
 
 	if (node->sort_id != 0) {
@@ -669,6 +678,12 @@
 			next_seq = seqs[i] + 1;
 		}
 	}
+
+	if (ctx->lowest_nonexpunged_zero == 0) {
+		/* we're handling only expunged zeros. if it causes us to
+		   renumber some existing sort IDs, don't save them. */
+		ctx->no_writing = TRUE;
+	}
 }
 
 void index_sort_list_finish_string(struct mail_search_sort_program *program)