优化计划查询避免 N+1 数据库访问

This commit is contained in:
2026-03-03 13:05:29 +08:00
parent 41ac21ea12
commit 325b7b5742
2 changed files with 45 additions and 45 deletions
+6 -4
View File
@@ -203,11 +203,13 @@
## 可重构/可优化项(非阻塞,但收益高)
### R1 计划查询存在 N+1 查询模式
### R1 计划查询存在 N+1 查询模式【已完成】
- 修复状态:✅ 已完成(2026-03-03
- 修复内容:
- `getPendingPlans``getHistoryPlans` 改为在 `weekendPlan.findMany` 中直接 `select room { name, code }`
- 移除逐条 `findUnique` 查房间的 N+1 查询路径。
- 证据:
- `src/lib/planQueries.ts:30-36``63-68`(每条计划单独查房间)
- 建议:
- 使用 `include` / 批量映射一次性拉取房间信息,减少 DB 往返。
- `src/lib/planQueries.ts` 已由“逐条房间查询”改为“单次查询带房间关系”。
### R2 `atomicUpdateRoom` 对 likes 的“全删全建”策略成本较高
- 证据: