From: Timo Sirainen Date: Wed, 19 Jul 2017 13:53:17 +0000 (+0300) Subject: *-login: Cache director_username_hash between KICK-DIRECTOR-HASH commands X-Git-Tag: 2.3.0.rc1~1101 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ec9429535e925610513bd6bfde6729e273082ccb;p=thirdparty%2Fdovecot%2Fcore.git *-login: Cache director_username_hash between KICK-DIRECTOR-HASH commands This should make the kicking much faster, which is important when director is moving thousands of users. --- diff --git a/src/login-common/client-common.h b/src/login-common/client-common.h index 90b57c8666..8250404e9b 100644 --- a/src/login-common/client-common.h +++ b/src/login-common/client-common.h @@ -191,6 +191,9 @@ struct client { as in global_alt_usernames. If some field doesn't exist, it's "". Can also be NULL if there are no user_* fields. */ const char **alt_usernames; + /* director_username_hash cached, if non-zero */ + unsigned int director_username_hash_cache; + bool destroyed:1; bool input_blocked:1; bool login_success:1; diff --git a/src/login-common/login-proxy.c b/src/login-common/login-proxy.c index 80553e3786..95c058e774 100644 --- a/src/login-common/login-proxy.c +++ b/src/login-common/login-proxy.c @@ -927,13 +927,18 @@ static bool director_username_hash(struct client *client, unsigned int *hash_r) { const char *error; - if (!mail_user_hash(client->virtual_user, - client->set->director_username_hash, - hash_r, &error)) { + if (client->director_username_hash_cache != 0) { + /* already set */ + } else if (!mail_user_hash(client->virtual_user, + client->set->director_username_hash, + &client->director_username_hash_cache, + &error)) { i_error("Failed to expand director_username_hash=%s: %s", client->set->director_username_hash, error); return FALSE; } + + *hash_r = client->director_username_hash_cache; return TRUE; }