mirror of
https://ghfast.top/https://github.com/aeroxw/easy_tdx_max.git
synced 2026-09-12 18:04:20 +08:00
fix(web-ui): 搜索索引前端超时 15s→120s + 后端单飞去重
问题:另一台机器首次加载报 'signal is aborted without reason'—— 不是取不到数据,是前端 AbortController 15 秒就掐断了请求,但遮罩 却告诉用户等 30-60 秒,自相矛盾。 修复: - 前端 fetchSearchIndex 超时 15s → 120s:遮罩本就是要等的,不能自己掐断 - 后端 _build_search_index 单飞去重:用 asyncio.Future 让 lifespan 预热 与 /security/search-index 端点请求共享同一任务,避免并发各爬一次全名单 (两个任务抢同一把 _execute_lock 反而互相拖慢) - lifespan 预热改为调 _build_search_index(复用单飞),加 120s 超时保护
This commit is contained in:
@@ -68,11 +68,15 @@ async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
|
||||
# 首次 get_security_list_all("all") 要几十次 TDX 协议往返(几十秒),
|
||||
# 后台提前跑,让本地缓存尽早建立。用户打开页面时大概率已就绪。
|
||||
# 用 create_task 不 await,服务立即可用;预热未完成时前端遮罩接管等待。
|
||||
# 与 /security/search-index 端点共享同一单飞任务(_build_search_index),
|
||||
# 避免预热和首次端点请求并发各爬一次全名单。
|
||||
import asyncio
|
||||
|
||||
async def _warmup_security_list() -> None:
|
||||
try:
|
||||
await client.get_security_list_all(pages="all")
|
||||
from easy_tdx.web.routers.market import _build_search_index
|
||||
|
||||
await asyncio.wait_for(_build_search_index(client), timeout=120)
|
||||
logger.info("Security list warmup done")
|
||||
except Exception:
|
||||
logger.warning("Security list warmup failed (non-fatal)", exc_info=True)
|
||||
|
||||
Reference in New Issue
Block a user