This commit is contained in:
yumoqing 2026-03-20 17:01:32 +08:00
parent 3b63971ac1
commit 7ce3980341

View File

@ -4,23 +4,6 @@ from ahserver.serverenv import ServerEnv
from appPublic.Singleton import SingletonDecorator
from appPublic.log import debug, exception, error
class CacheUP:
def __init__(self, userid, paths):
self.touch_time = time.time()
self.userid = userid
self.paths = paths
if userid is None:
sql
self.sql_all = """select a.id,b.path from users a, userrole c, rolepermission d, permission b
where a.id = c.userid
and c.roleid = d.roleid
and d.permid = b.id"""
def get_paths(self):
self.touch_time = time.time()
return self.paths
class CacheRolePath:
@SingletonDecorator
class UserPermisions:
def __init__(self, max_cache_user=10000):
@ -77,35 +60,3 @@ where a.id = c.userid
return self.check_roles_path(roles, path)
async def get_user_perms_paths(self, userid):
cup = await self.get_cached_user_cup(userid)
if cup:
return cup.get_paths()
cup = await self.load_user_cup(userid)
return cup.get_paths()
async def refresh_all_cup(self):
db = DBPools()
env = ServerEnv()
dbname = env.get_module_dbname('rbac')
sql = """select a.id,b.path from users a, userrole c, rolepermission d, permission b
where a.id = c.userid
and c.roleid = d.roleid
and d.permid = b.id order by a.id, b.path"""
async with db.sqlorContext(dbname) as sor:
ups = await sor.sqlExe(sql, {'userid': userid})
userid = ''
paths = []
for u in ups:
if userid != u.id:
if userid != '':
cup = CacheUP(userid, paths)
self.cups[userid] = cup
if len(self.cups.keys()) >= self.max_cache_user:
break
userid = u.id
paths = []
userid = u.id
paths.append(u.path)