fix: 提交列表和删除提交的慢查询,素材上传、登出和几处前端加载问题
性能(6 万条提交、18 万条消息的测试库上测的) - 提交列表 join task_task 时用 +s.task_id,不再从任务表出发经 task_id 单列索引回表读 html/css/js 大行,改走 slim 覆盖索引:翻页 260-700ms → 4-18ms - 删除提交时先查出 id 再按等值删关联行:prompt_message.submission_id 几乎全是 NULL, 写成 IN (子查询) 时统计信息会让 SQLite 扫整张表 bug - 提交列表排序加 rowid 作次级键,同分的提交翻页不再重复或遗漏 - 素材文件名只允许字母数字和 - _ .(否则 422),覆盖同名文件改成写临时文件再 rename; 前端删除时对名字做 URL 编码 - 刷新 token 只是网络失败时不再强制登出;退出请求失败时界面也显示为已退出 - 历史面板加载中收到的刷新不再丢掉;成绩册只用最后一次请求的结果,打开时不再加载两次 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
40f3063b91
commit
03878f6cc2
8 files changed
+124
-41
No files matched your search
@@ -53,9 +53,11 @@ const SUBMISSION_SELECT = `SELECT s.id, s.user_id, u.username, s.task_id, t.disp
|
||||
s.view_count, s.created, s.modified,
|
||||
(SELECT r.score FROM submission_rating r WHERE r.user_id = $me AND r.submission_id = s.id LIMIT 1) AS my_score`
|
||||
|
||||
// +s.task_id:不让 SQLite 从 task_task 出发、用 task_id 单列索引去找提交(那样要回表读
|
||||
// html/css/js 大行,6 万条提交时列表要几百毫秒),改走 slim 覆盖索引;按 task_id 筛选不受影响
|
||||
const SUBMISSION_FROM = `FROM submission_submission s
|
||||
JOIN account_user u ON u.id = s.user_id
|
||||
JOIN task_task t ON t.id = s.task_id`
|
||||
JOIN task_task t ON t.id = +s.task_id`
|
||||
|
||||
function submissionOut(s: any) {
|
||||
return {
|
||||
@@ -269,7 +271,8 @@ router.get("/", (c) => {
|
||||
score: "s.score ASC",
|
||||
"-created": "s.created DESC",
|
||||
}
|
||||
const orderBy = orderings[f.ordering ?? ""] ?? "s.created DESC"
|
||||
// 同分、同一时间的提交很多,加上 rowid 让排序唯一,翻页才不会重复或漏掉
|
||||
const orderBy = `${orderings[f.ordering ?? ""] ?? "s.created DESC"}, s.rowid DESC`
|
||||
const whereSql = where.length ? `WHERE ${where.join(" AND ")}` : ""
|
||||
const { limit, offset } = pageWindow(f)
|
||||
|
||||
|
||||
Reference in new issue
Block a user