From: Michael Tremer Date: Tue, 7 May 2019 10:19:30 +0000 (+0100) Subject: accounts: Cache group memberships X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=819daf36f96963779512c852317aa8c5164e2aae;p=ipfire.org.git accounts: Cache group memberships Signed-off-by: Michael Tremer --- diff --git a/src/backend/accounts.py b/src/backend/accounts.py index c278c07d..dfdebf98 100644 --- a/src/backend/accounts.py +++ b/src/backend/accounts.py @@ -427,6 +427,19 @@ class Account(Object): @lazy_property def groups(self): + groups = self.memcache.get("accounts:%s:groups" % self.dn) + if groups: + return groups + + # Fetch groups from LDAP + groups = self._get_groups() + + # Cache groups for 5 min + self.memcache.set("accounts:%s:groups" % self.dn, groups, 300) + + return groups + + def _get_groups(self): groups = [] res = self.accounts._query("(&(objectClass=posixGroup) \