性能优化(一)基础层:事件循环解冻 + 规则编译期 API + 接口小优化
- db.py 四端点、ai.py explain/gen_regex 从 async def 改 def:内部是同步阻塞的
DB 建连(最长 10s)与 LLM 调用(最长 30s×2),挂事件循环上会冻结整个后端;
def 走 FastAPI 线程池。explain 按 /ai/rule 同款补 run_in_executor
- rule_runner 新增 compile_rule() 编译期 API(regex→编译好的 Pattern;
number/date/string→沙箱 exec 一次取出 check 闭包,skip_null/date 归一化烘焙
进闭包);run_rule 收敛为薄封装(单值测试端点继续用);_exec_user_function
拆为 _compile_user_function + _sandbox_namespace
- tasks.py list_tasks 批量计数(逐任务 3~4 条 SQL → 3 条 group_by 聚合)
- app.py 加 GZipMiddleware(minimum_size=1024)
检测引擎接入预编译(queries.py)与流式扫描在下一笔。
Co-Authored-By:
Claude Fable 5 <noreply@anthropic.com>
Showing
This diff is collapsed.
Please register or sign in to comment