dovecot-2.2: quota: Added a kludge to avoid recalculating quota.

dovecot at dovecot.org dovecot at dovecot.org
Sun May 20 03:26:30 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/fb70195b5d47
changeset: 14374:fb70195b5d47
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Mar 22 18:05:08 2012 +0200
description:
quota: Added a kludge to avoid recalculating quota.

diffstat:

 src/lib-storage/index/dbox-multi/mdbox-sync.c      |  2 ++
 src/lib-storage/index/dbox-single/sdbox-sync.c     |  4 ++++
 src/lib-storage/index/maildir/maildir-sync-index.c |  2 ++
 src/lib-storage/mail-storage-private.h             |  2 ++
 src/plugins/quota/quota-storage.c                  |  8 ++++++++
 5 files changed, 18 insertions(+), 0 deletions(-)

diffs (97 lines):

diff -r 39db9e4c2283 -r fb70195b5d47 src/lib-storage/index/dbox-multi/mdbox-sync.c
--- a/src/lib-storage/index/dbox-multi/mdbox-sync.c	Thu Mar 22 17:44:51 2012 +0200
+++ b/src/lib-storage/index/dbox-multi/mdbox-sync.c	Thu Mar 22 18:05:08 2012 +0200
@@ -115,11 +115,13 @@
 
 	if (box->v.sync_notify != NULL) {
 		/* do notifications after commit finished successfully */
+		box->tmp_sync_view = ctx->sync_view;
 		seq_range_array_iter_init(&iter, &ctx->expunged_seqs); n = 0;
 		while (seq_range_array_iter_nth(&iter, n++, &seq)) {
 			mail_index_lookup_uid(ctx->sync_view, seq, &uid);
 			box->v.sync_notify(box, uid, MAILBOX_SYNC_TYPE_EXPUNGE);
 		}
+		box->tmp_sync_view = NULL;
 	}
 	return 0;
 }
diff -r 39db9e4c2283 -r fb70195b5d47 src/lib-storage/index/dbox-single/sdbox-sync.c
--- a/src/lib-storage/index/dbox-single/sdbox-sync.c	Thu Mar 22 17:44:51 2012 +0200
+++ b/src/lib-storage/index/dbox-single/sdbox-sync.c	Thu Mar 22 18:05:08 2012 +0200
@@ -150,10 +150,12 @@
 
 	/* NOTE: Index is no longer locked. Multiple processes may be unlinking
 	   the files at the same time. */
+	ctx->mbox->box.tmp_sync_view = ctx->sync_view;
 	array_foreach(&ctx->expunged_uids, uidp)
 		dbox_sync_file_expunge(ctx, *uidp);
 	if (ctx->mbox->box.v.sync_notify != NULL)
 		ctx->mbox->box.v.sync_notify(&ctx->mbox->box, 0, 0);
+	ctx->mbox->box.tmp_sync_view = NULL;
 }
 
 static int
@@ -262,11 +264,13 @@
 	*_ctx = NULL;
 
 	if (success) {
+		mail_index_view_ref(ctx->sync_view);
 		if (mail_index_sync_commit(&ctx->index_sync_ctx) < 0) {
 			mail_storage_set_index_error(&ctx->mbox->box);
 			ret = -1;
 		} else {
 			dbox_sync_expunge_files(ctx);
+			mail_index_view_close(&ctx->sync_view);
 		}
 	} else {
 		mail_index_sync_rollback(&ctx->index_sync_ctx);
diff -r 39db9e4c2283 -r fb70195b5d47 src/lib-storage/index/maildir/maildir-sync-index.c
--- a/src/lib-storage/index/maildir/maildir-sync-index.c	Thu Mar 22 17:44:51 2012 +0200
+++ b/src/lib-storage/index/maildir/maildir-sync-index.c	Thu Mar 22 18:05:08 2012 +0200
@@ -492,6 +492,7 @@
 	}
 	hdr_next_uid = hdr->next_uid;
 
+	ctx->mbox->box.tmp_sync_view = view;
 	private_flags_mask = mailbox_get_private_flags_mask(&mbox->box);
 	time_before_sync = time(NULL);
 	mbox->syncing_commit = TRUE;
@@ -647,6 +648,7 @@
 
 	if (mbox->box.v.sync_notify != NULL)
 		mbox->box.v.sync_notify(&mbox->box, 0, 0);
+	ctx->mbox->box.tmp_sync_view = NULL;
 
 	/* check cur/ mtime later. if we came here from saving messages they
 	   could still be moved to cur/ directory. */
diff -r 39db9e4c2283 -r fb70195b5d47 src/lib-storage/mail-storage-private.h
--- a/src/lib-storage/mail-storage-private.h	Thu Mar 22 17:44:51 2012 +0200
+++ b/src/lib-storage/mail-storage-private.h	Thu Mar 22 18:05:08 2012 +0200
@@ -240,6 +240,8 @@
 	unsigned int transaction_count;
 	enum mailbox_feature enabled_features;
 
+	struct mail_index_view *tmp_sync_view;
+
 	/* Mailbox notification settings: */
 	unsigned int notify_min_interval;
 	mailbox_notify_callback_t *notify_callback;
diff -r 39db9e4c2283 -r fb70195b5d47 src/plugins/quota/quota-storage.c
--- a/src/plugins/quota/quota-storage.c	Thu Mar 22 17:44:51 2012 +0200
+++ b/src/plugins/quota/quota-storage.c	Thu Mar 22 18:05:08 2012 +0200
@@ -298,7 +298,15 @@
 
 	/* try to look up the size. this works only if it's cached. */
 	if (qbox->expunge_qt->tmp_mail == NULL) {
+		/* FIXME: ugly kludge to open the transaction for sync_view.
+		   box->view may not have all the new messages that
+		   sync_notify() notifies about, and those messages would
+		   cause a quota recalculation. */
+		struct mail_index_view *box_view = box->view;
+		if (box->tmp_sync_view != NULL)
+			box->view = box->tmp_sync_view;
 		qbox->expunge_trans = mailbox_transaction_begin(box, 0);
+		box->view = box_view;
 		qbox->expunge_qt->tmp_mail =
 			mail_alloc(qbox->expunge_trans,
 				   MAIL_FETCH_PHYSICAL_SIZE, NULL);


More information about the dovecot-cvs mailing list