]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
*-login: Cache director_username_hash between KICK-DIRECTOR-HASH commands
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 19 Jul 2017 13:53:17 +0000 (16:53 +0300)
committerTimo Sirainen <tss@dovecot.fi>
Tue, 5 Sep 2017 14:41:50 +0000 (17:41 +0300)
This should make the kicking much faster, which is important when director
is moving thousands of users.

src/login-common/client-common.h
src/login-common/login-proxy.c

index 90b57c86662eeced41c2bcc7bfff910d0d401060..8250404e9bcb259db2af838a1e13f86eba25f779 100644 (file)
@@ -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;
index 80553e37862bd742ee7ba3a9a241da0ff576c9d8..95c058e7743af64bf952916c6be7a27b01364de4 100644 (file)
@@ -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;
 }