perf: 提交列表等查询改走覆盖索引,避免读取 html/css/js 大行

SQLite 把 html/css/js 存在行内,而 user_id、task_id、flag 等列排在它们后面,
读这些列也要先读完整段代码;线上库也没有统计信息,规划器常挑错索引。

- 新增覆盖索引 submission_submission_slim
- 提交列表、随机打分先在索引上取 rowid,再只读这一页 / 这一行的完整内容
- 列表的 flag / zone 筛选用一元 + 避开单列索引
- 打开数据库时执行 PRAGMA optimize,之后每小时一次

线上备份实测:提交列表 844 ms → 6 ms,打分后重算分数 11.5 ms → 0.2 ms。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
xuyueandClaude Opus 5.5 committed 2026-10-26 18:36:54 +08:00
1 parent 4b8109caaa
commit e6a3da14b0
3 files changed
+33 -13

No files matched your search

+4
View File
@@ -1,5 +1,6 @@
import { app } from "./app"
import { config } from "./config"
import { db } from "./db"
import { upgrade, websocket, type WsData } from "./ws"
const server = Bun.serve<WsData>({
@@ -16,4 +17,7 @@ const server = Bun.serve<WsData>({
websocket,
})
// 长期运行的连接按 SQLite 文档建议定期刷新统计信息
setInterval(() => db.run("PRAGMA optimize"), 60 * 60 * 1000)
console.log(`webpreview server listening on http://localhost:${server.port}`)