changeset 20689:6006f03b7757

stats: Fix user login counters Before we would count all users twice, because the same counters would get increment in both CONNECT and ADD-USER. Now we do not increment them at all on ADD-USER.
author Aki Tuomi <aki.tuomi@dovecot.fi>
date Sun, 28 Aug 2016 19:14:08 +0300
parents f5aefbab9677
children 50456ea55fec
files src/stats/mail-domain.c src/stats/mail-session.c src/stats/mail-user.c
diffstat 3 files changed, 6 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/stats/mail-domain.c	Wed Aug 24 03:56:44 2016 -0400
+++ b/src/stats/mail-domain.c	Sun Aug 28 19:14:08 2016 +0300
@@ -25,7 +25,6 @@
 
 	domain = hash_table_lookup(mail_domains_hash, name);
 	if (domain != NULL) {
-		mail_domain_login(domain);
 		return domain;
 	}
 
@@ -37,7 +36,6 @@
 	hash_table_insert(mail_domains_hash, domain->name, domain);
 	DLLIST_PREPEND_FULL(&stable_mail_domains, domain,
 			    stable_prev, stable_next);
-	mail_domain_login(domain);
 	global_memory_alloc(mail_domain_memsize(domain));
 	return domain;
 }
@@ -46,7 +44,6 @@
 {
 	domain->num_logins++;
 	domain->num_connected_sessions++;
-	mail_global_login();
 	mail_domain_refresh(domain, NULL);
 }
 
--- a/src/stats/mail-session.c	Wed Aug 24 03:56:44 2016 -0400
+++ b/src/stats/mail-session.c	Sun Aug 28 19:14:08 2016 +0300
@@ -13,6 +13,7 @@
 #include "mail-user.h"
 #include "mail-ip.h"
 #include "mail-session.h"
+#include "mail-domain.h"
 
 /* If session doesn't receive any updates for this long, assume that the
    process associated with it has crashed, and forcibly disconnect the
@@ -107,6 +108,9 @@
 				       mail_session_idle_timeout, session);
 
 	session->user = mail_user_login(args[1]);
+	session->user->num_logins++;
+	mail_domain_login(session->user->domain);
+
 	for (i = 3; args[i] != NULL; i++) {
 		if (strncmp(args[i], "rip=", 4) == 0 &&
 		    net_addr2ip(args[i] + 4, &ip) == 0)
@@ -127,6 +131,8 @@
 		mail_ip_ref(session->ip);
 	}
 	global_memory_alloc(mail_session_memsize(session));
+
+	mail_global_login();
 	return 0;
 }
 
--- a/src/stats/mail-user.c	Wed Aug 24 03:56:44 2016 -0400
+++ b/src/stats/mail-user.c	Sun Aug 28 19:14:08 2016 +0300
@@ -29,9 +29,7 @@
 
 	user = hash_table_lookup(mail_users_hash, username);
 	if (user != NULL) {
-		user->num_logins++;
 		mail_user_refresh(user, NULL);
-		mail_domain_login(user->domain);
 		return user;
 	}
 
@@ -56,7 +54,6 @@
 			    domain_prev, domain_next);
 	mail_domain_ref(user->domain);
 
-	user->num_logins++;
 	user->last_update = ioloop_timeval;
 	global_memory_alloc(mail_user_memsize(user));
 	return user;