From 5470d3be330029d06d8e3d957a769fd6140ce890 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 7 Aug 2025 18:08:17 +0800 Subject: [PATCH] bugfix --- uapi/appapi.py | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/uapi/appapi.py b/uapi/appapi.py index 2dcd132..cda0bd3 100644 --- a/uapi/appapi.py +++ b/uapi/appapi.py @@ -31,13 +31,14 @@ async def sync_users(request, upappid, userid): upapp = await get_upapp(sor, upappid) class UAPI: - def __init__(self, request, env=DictObject()): + def __init__(self, request, env=DictObject(), sor=None): self.request = request self.te = MyTemplateEngine([], env=env) self.env = env self.env.request.request = request self.auth_api = None self.auth_ret = None + self.sor = sor async def rendertmpl(self, tmplstr, params={}): if tmplstr is None: @@ -47,13 +48,15 @@ class UAPI: te = MyTemplateEngine([], env=self.env) return te.renders(tmplstr, ns) - async def get_uapis(self, upappid, apiname, callerid, params={}): + async def get_uapis(self, sor, upappid, apiname, callerid, params={}): self.env.update(params) db = DBPools() - dbname = get_dbname() uapi = None auth_uapi = None - async with db.sqlorContext(dbname) as sor: + if self.sor is None: + dbname = get_dbname() + self.sor = db.sqlorContext(dbname) + async with self.sor as sor: upapps = await sor.R('upapp', {'id': upappid}) if len(upapps) == 0: e = Exceptions(f'{upappid=}, {apiname=}, {callerid=} upapp not found') @@ -92,8 +95,18 @@ class UAPI: async def __call__(self, upappid, apiname, callerid, params={}): """ """ - auth_uapi, uapi = await self.get_uapis(upapiid, apiname, + auth_uapi = uapi = None + if self.sor: + auth_uapi, uapi = await self.get_uapis(self.sor, upapiid, apiname, callerid, params=params) + else: + dbname = get_dbname() + self.sor = db.sqlorContext(dbname) + async with self.sor as sor: + auth_uapi, uapi = await self.get_uapis(self.sor, + upapiid, apiname, + callerid, params=params) + if uapi is None: return if auth_uapi: