changeset 8014:cb2650c20a58 HEAD

Recreate dovecot-uidlist if updating it would shrink the file more than 25%.
author Timo Sirainen <tss@iki.fi>
date Wed, 18 Jun 2008 03:18:56 +0300
parents 7513ad244f0f
children 73b4fe95a6dd
files src/lib-storage/index/maildir/maildir-uidlist.c
diffstat 1 files changed, 15 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/maildir/maildir-uidlist.c	Wed Jun 18 03:05:17 2008 +0300
+++ b/src/lib-storage/index/maildir/maildir-uidlist.c	Wed Jun 18 03:18:56 2008 +0300
@@ -1022,6 +1022,7 @@
 	iter->next += first_idx;
 
 	while (maildir_uidlist_iter_next_rec(iter, &rec)) {
+		uidlist->read_records_count++;
 		str_truncate(str, 0);
 		str_printfa(str, "%u", rec->uid);
 		if (rec->extensions != NULL) {
@@ -1101,6 +1102,7 @@
 		}
 	}
 
+	uidlist->read_records_count = 0;
 	ret = maildir_uidlist_write_fd(uidlist, fd, temp_path, 0, &file_size);
 	if (ret == 0) {
 		if (rename(temp_path, uidlist->path) < 0) {
@@ -1155,10 +1157,19 @@
 	return ret;
 }
 
+static bool maildir_uidlist_want_compress(struct maildir_uidlist_sync_ctx *ctx)
+{
+	unsigned int min_rewrite_count;
+
+	min_rewrite_count =
+		(ctx->uidlist->read_records_count + ctx->new_files_count) *
+		UIDLIST_COMPRESS_PERCENTAGE / 100;
+	return min_rewrite_count >= array_count(&ctx->uidlist->records);
+}
+
 static bool maildir_uidlist_want_recreate(struct maildir_uidlist_sync_ctx *ctx)
 {
 	struct maildir_uidlist *uidlist = ctx->uidlist;
-	unsigned int min_rewrite_count;
 
 	if (!uidlist->initial_read)
 		return FALSE;
@@ -1168,10 +1179,7 @@
 	    ctx->finish_change_counter != uidlist->change_counter)
 		return TRUE;
 
-	min_rewrite_count =
-		(uidlist->read_records_count + ctx->new_files_count) *
-		UIDLIST_COMPRESS_PERCENTAGE / 100;
-	return min_rewrite_count >= array_count(&uidlist->records);
+	return maildir_uidlist_want_compress(ctx);
 }
 
 static int maildir_uidlist_sync_update(struct maildir_uidlist_sync_ctx *ctx)
@@ -1570,7 +1578,8 @@
 	ctx->uidlist->initial_sync = TRUE;
 
 	i_assert(ctx->locked || !ctx->changed);
-	if ((ctx->changed || ctx->uidlist->recreate) &&
+	if ((ctx->changed || ctx->uidlist->recreate ||
+	     maildir_uidlist_want_compress(ctx)) &&
 	    !ctx->failed && ctx->locked) T_BEGIN {
 		if (maildir_uidlist_sync_update(ctx) < 0)
 			ctx->failed = TRUE;