feat: respect module_cache config for UAPI cache

This commit is contained in:
yumoqing 2026-05-29 17:59:26 +08:00
parent 4892a4e460
commit 77b4b14525

View File

@ -8,10 +8,23 @@ from appPublic.streamhttpclient import StreamHttpClient, liner
from appPublic.dictObject import DictObject from appPublic.dictObject import DictObject
from appPublic.log import debug, exception, error from appPublic.log import debug, exception, error
from appPublic.aes import aes_encode_b64 from appPublic.aes import aes_encode_b64
from appPublic.jsonConfig import getConfig
from ahserver.globalEnv import password_decode from ahserver.globalEnv import password_decode
from ahserver.serverenv import get_serverenv, ServerEnv from ahserver.serverenv import get_serverenv, ServerEnv
from random import randint from random import randint
def _cache_enabled():
"""Check if cache is enabled for uapi module in config.json"""
try:
config = getConfig()
module_cache = config.module_cache
if module_cache is None:
return True
return getattr(module_cache, 'uapi', True)
except Exception:
return True
async def get_deerer(upappid, callerid): async def get_deerer(upappid, callerid):
db = DBPools() db = DBPools()
dbname = get_dbname() dbname = get_dbname()
@ -69,9 +82,10 @@ class UAPIData:
async def get_apiusers(self, appid, orgid=None): async def get_apiusers(self, appid, orgid=None):
key = appid key = appid
d = self.org_users.get(key) if _cache_enabled():
if d: d = self.org_users.get(key)
return d if d:
return d
env = ServerEnv() env = ServerEnv()
async with get_sor_context(env, 'uapi') as sor: async with get_sor_context(env, 'uapi') as sor:
sql = """select sql = """select
@ -122,9 +136,10 @@ where b.orgid = c.ownerid
async def get_api(self, appid, apiname): async def get_api(self, appid, apiname):
key = f'{appid}.{apiname}' key = f'{appid}.{apiname}'
api = self.apidata.get(key) if _cache_enabled():
if api: api = self.apidata.get(key)
return api if api:
return api
env = ServerEnv() env = ServerEnv()
async with get_sor_context(env, 'uapi') as sor: async with get_sor_context(env, 'uapi') as sor:
d = await sor_get_uapi(sor, appid, apiname) d = await sor_get_uapi(sor, appid, apiname)