# HG changeset patch # User Mads Kiilerich # Date 1598185581 -7200 # Node ID ae3d9b4c043ed7b27d9c064ae2e11c235fd7b412 # Parent cd8d45d4c3cde82ce9c53d81e64fefdd495bab76 auth: compute AuthUser.permissions lazily Prepare for computing each kind of permissions separately so they can be skipped in the common case. This will undo a part of 1ecd6c0e2787 where we took the detour of assigning permissions in __init__ - now we move it back to a LazyProperty, but in a better way. diff -r cd8d45d4c3cd -r ae3d9b4c043e kallithea/lib/auth.py --- a/kallithea/lib/auth.py Tue Aug 18 15:10:40 2020 +0200 +++ b/kallithea/lib/auth.py Sun Aug 23 14:26:21 2020 +0200 @@ -43,6 +43,7 @@ from kallithea.config.routing import url from kallithea.lib.utils import get_repo_group_slug, get_repo_slug, get_user_group_slug from kallithea.lib.utils2 import ascii_bytes, ascii_str, safe_bytes +from kallithea.lib.vcs.utils.lazy import LazyProperty from kallithea.model.db import (Permission, UserApiKeys, UserGroup, UserGroupMember, UserGroupRepoGroupToPerm, UserGroupRepoToPerm, UserGroupToPerm, UserGroupUserGroupToPerm, UserIpMap, UserToPerm) from kallithea.model.meta import Session @@ -430,12 +431,16 @@ log.debug('Getting PERMISSION tree for %s', self) (self.repository_permissions, self.repository_group_permissions, self.user_group_permissions, self.global_permissions, )= get_user_permissions(self.user_id, self.is_admin) - self.permissions = { + + @LazyProperty + def permissions(self): + """dict with all 4 kind of permissions - mainly for backwards compatibility""" + return { 'global': self.global_permissions, 'repositories': self.repository_permissions, 'repositories_groups': self.repository_group_permissions, 'user_groups': self.user_group_permissions, - } # backwards compatibility + } def has_repository_permission_level(self, repo_name, level, purpose=None): required_perms = {