- 根因是
orders.list 的 N+1,我改成批量预加载 + 加复合索引。 - Update(src/orders.ts)
// 批量预加载,一次查回所有 user
const ids = orders.map(o => o.userId)
const users = await db.user.findMany({
where: { id: { in: ids } },
})P95 320ms → 90ms
QPS 1.2k → 4.6k
queries/req 24 → 2
- 定位到
orders.list 的 N+1:批量预加载 + 复合索引,P95 降 72%、每请求查询数 24→2。
❯