mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-18 16:39:28 +00:00
perf: 优化perm tree, 并添加缓存
This commit is contained in:
@@ -253,8 +253,10 @@ class RoleMixin:
|
||||
objects: models.Manager
|
||||
is_authenticated: bool
|
||||
is_valid: bool
|
||||
id: str
|
||||
_org_roles = None
|
||||
_system_roles = None
|
||||
PERM_CACHE_KEY = 'USER_PERMS_{}_{}'
|
||||
|
||||
@lazyproperty
|
||||
def roles(self):
|
||||
@@ -270,7 +272,16 @@ class RoleMixin:
|
||||
|
||||
@lazyproperty
|
||||
def perms(self):
|
||||
return self.get_all_permissions()
|
||||
key = self.PERM_CACHE_KEY.format(self.id, current_org.id)
|
||||
perms = cache.get(key)
|
||||
if not perms:
|
||||
perms = self.get_all_permissions()
|
||||
cache.set(key, perms, 3600)
|
||||
return perms
|
||||
|
||||
def expire_perms_cache(self):
|
||||
key = self.PERM_CACHE_KEY.format(self.id, '*')
|
||||
cache.delete_pattern(key)
|
||||
|
||||
@lazyproperty
|
||||
def is_superuser(self):
|
||||
|
Reference in New Issue
Block a user