fix: _get_realtime_snapshot加请求级缓存,一次页面渲染只查一次DB

This commit is contained in:
yumoqing 2026-07-22 13:39:37 +08:00
parent 305395ca99
commit 482c0fac8b

View File

@ -250,12 +250,17 @@ async def api_distributor_customers(request):
# ── Jinja2 模板函数(实时,角色感知)──
async def _get_realtime_snapshot(request):
"""一次查询返回全部实时指标(含角色)各j2函数复用同一结果"""
"""一次查询返回全部实时指标(含角色),同一请求内缓存复用"""
cache_key = '_sage_datamart_rt_cache'
if cache_key in request:
return request[cache_key]
env = request._run_ns
scope, org_filter = await _resolve_view(request)
today = env.curDateString()
async with get_sor_context(env, MODULE_NAME) as sor:
return await get_realtime_stats(sor, today, scope, org_filter)
result = await get_realtime_stats(sor, today, scope, org_filter)
request[cache_key] = result
return result
async def j2_realtime_calls(request):