# HG changeset patch # User Mads Kiilerich # Date 1586652236 -7200 # Node ID f6be760c786cc800082b76e1a26def63bac0ad71 # Parent aec1b9c9ffe6ad93ba4dbcc4511395b48d12affa auth: simplify AuthUser.permissions and how it actually never use cache diff -r aec1b9c9ffe6 -r f6be760c786c kallithea/lib/auth.py --- a/kallithea/lib/auth.py Sun Oct 20 04:57:04 2019 +0200 +++ b/kallithea/lib/auth.py Sun Apr 12 02:43:56 2020 +0200 @@ -40,7 +40,7 @@ from webob.exc import HTTPForbidden, HTTPFound from kallithea.config.routing import url -from kallithea.lib.utils import conditional_cache, get_repo_group_slug, get_repo_slug, get_user_group_slug +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, User, UserApiKeys, UserGroup, UserGroupMember, UserGroupRepoGroupToPerm, UserGroupRepoToPerm, UserGroupToPerm, @@ -433,7 +433,15 @@ @LazyProperty def permissions(self): - return self.__get_perms(user=self, cache=False) + """ + Fills user permission attribute with permissions taken from database + works for permissions given for repositories, and for permissions that + are granted to groups + + :param user: `AuthUser` instance + """ + log.debug('Getting PERMISSION tree for %s', self) + return _cached_perms_data(self.user_id, self.is_admin) def has_repository_permission_level(self, repo_name, level, purpose=None): required_perms = { @@ -475,22 +483,6 @@ def api_keys(self): return self._get_api_keys() - def __get_perms(self, user, cache=False): - """ - Fills user permission attribute with permissions taken from database - works for permissions given for repositories, and for permissions that - are granted to groups - - :param user: `AuthUser` instance - """ - user_id = user.user_id - user_is_admin = user.is_admin - - log.debug('Getting PERMISSION tree') - compute = conditional_cache('short_term', 'cache_desc', - condition=cache, func=_cached_perms_data) - return compute(user_id, user_is_admin) - def _get_api_keys(self): api_keys = [self.api_key] for api_key in UserApiKeys.query() \ diff -r aec1b9c9ffe6 -r f6be760c786c kallithea/lib/utils.py --- a/kallithea/lib/utils.py Sun Oct 20 04:57:04 2019 +0200 +++ b/kallithea/lib/utils.py Sun Apr 12 02:43:56 2020 +0200 @@ -610,9 +610,8 @@ def conditional_cache(region, prefix, condition, func): """ - Conditional caching function use like:: - def _c(arg): + def func(arg): #heavy computation function return data @@ -623,8 +622,7 @@ :param region: name of cache region :param prefix: cache region prefix :param condition: condition for cache to be triggered, and return data cached - :param func: wrapped heavy function to compute - + :param func: heavy function to compute """ wrapped = func if condition: