dovecot-2.1: stats: Refresh user statistics during long maildir ...

dovecot at dovecot.org dovecot at dovecot.org
Fri Oct 26 12:09:32 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.1/rev/b1b693a69c5f
changeset: 14788:b1b693a69c5f
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Oct 26 12:09:03 2012 +0300
description:
stats: Refresh user statistics during long maildir syncs.

diffstat:

 src/plugins/stats/stats-plugin.c |  36 ++++++++++++++++++++++++++++++++++++
 1 files changed, 36 insertions(+), 0 deletions(-)

diffs (60 lines):

diff -r 0efb98659a1f -r b1b693a69c5f src/plugins/stats/stats-plugin.c
--- a/src/plugins/stats/stats-plugin.c	Fri Oct 26 11:43:05 2012 +0300
+++ b/src/plugins/stats/stats-plugin.c	Fri Oct 26 12:09:03 2012 +0300
@@ -33,6 +33,13 @@
 	struct mailbox_transaction_stats prev_stats;
 };
 
+struct stats_storage {
+	union mail_storage_module_context module_ctx;
+
+	struct mail_storage_callbacks old_callbacks;
+	void *old_context;
+};
+
 struct stats_mailbox {
 	union mailbox_module_context module_ctx;
 };
@@ -431,6 +438,33 @@
 	return ret;
 }
 
+static void
+stats_notify_ok(struct mailbox *box, const char *text, void *context)
+{
+	struct stats_storage *sstorage = STATS_CONTEXT(box->storage);
+
+	/* most importantly we want to refresh stats for very long running
+	   mailbox syncs */
+	session_stats_refresh(box->storage->user);
+
+	if (sstorage->old_callbacks.notify_ok != NULL)
+		sstorage->old_callbacks.notify_ok(box, text, context);
+}
+
+static void stats_register_notify_callbacks(struct mail_storage *storage)
+{
+	struct stats_storage *sstorage = STATS_CONTEXT(storage);
+
+	if (sstorage != NULL)
+		return;
+
+	sstorage = p_new(storage->pool, struct stats_storage, 1);
+	sstorage->old_callbacks = storage->callbacks;
+	storage->callbacks.notify_ok = stats_notify_ok;
+
+	MODULE_CONTEXT_SET(storage, stats_storage_module, sstorage);
+}
+
 static void stats_mailbox_allocated(struct mailbox *box)
 {
 	struct mailbox_vfuncs *v = box->vlast;
@@ -440,6 +474,8 @@
 	if (suser == NULL)
 		return;
 
+	stats_register_notify_callbacks(box->storage);
+
 	sbox = p_new(box->pool, struct stats_mailbox, 1);
 	sbox->module_ctx.super = *v;
 	box->vlast = &sbox->module_ctx.super;


More information about the dovecot-cvs mailing list