From 66d51dfd83fb4fe36cb1af979f7a6efa852e6c3f Mon Sep 17 00:00:00 2001 From: yuetsh <517252939@qq.com> Date: Tue, 25 Aug 2026 19:02:37 -0600 Subject: [PATCH] =?UTF-8?q?chore(=E8=B4=A6=E5=8F=B7):=20=E5=88=A0=E6=8E=89?= =?UTF-8?q?=E6=B2=A1=E4=BA=BA=E8=B0=83=E7=9A=84=20refreshUserProblemDispla?= =?UTF-8?q?yIds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit oj/api.ts 里那句 `// TODO: 这个API有问题` 是从 ojnext 原样搬过来的,**说的是 旧后端的 bug,移植时已经修掉了**。旧的 ProfileProblemDisplayIDRefreshAPI: ids = list(acm_problems.keys()) display_ids = [... filter(id__in=ids, visible=True).values_list("_id")] id_map = dict(zip(ids, display_ids)) zip 把「dict 键顺序」和「查询返回顺序」硬凑成对,题目一旦被隐藏或删除 display_ids 就比 ids 短 —— 轻则编号张冠李戴写进库,重则 id_map[k] KeyError。 account.ts 那版是按 id 建 Map、查不到就不动,是对的。留着这条 TODO 只会让 下一个人去查一个不存在的 bug。 顺带查出来:这个函数**两代前端都只有定义、没有任何调用点**。端点清单把 /api/profile/fresh_display_id 标成「前端有调用」是提取脚本匹配到了函数定义 里的 http.get 字面量,不是调用,属于假阳性。前端这个死导出删掉。 后端端点保留 —— 教师改了题目编号之后,学生 acm_problems_status 里缓存的 _id 只有它能刷,是这份缓存唯一的入口。加注释写清它是干嘛的、为什么现在没人 调(要接 UI 从这儿开始)、以及旧后端那版错在哪。 Co-Authored-By: Claude Opus 5 --- apps/api/src/routes/account.ts | 12 ++++++++++++ apps/web/src/oj/api.ts | 5 ----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/apps/api/src/routes/account.ts b/apps/api/src/routes/account.ts index b565d33..8ebe032 100644 --- a/apps/api/src/routes/account.ts +++ b/apps/api/src/routes/account.ts @@ -291,6 +291,18 @@ accountRoutes.get("/problems/:displayId/rank", requireAuth, async (c) => { return success(c, problemRankSchema.parse({ className, rank, classAcCount: classCount?.value ?? 0, allAcCount: all?.value ?? 0 })) }) +/** + * 把 `user_profile.acm_problems_status` 里缓存的题目编号刷成当前值 —— + * 教师改了题目的 `_id`(后台「修改题目编号」)之后,学生个人主页上的那份缓存会变旧。 + * + * **目前没有任何前端在调用它**,两代前端都只定义了函数、没有调用点。保留是因为 + * 它是唯一能修这份缓存的入口;要接 UI 的话,从这里开始。 + * + * 旧后端 `ProfileProblemDisplayIDRefreshAPI` 这段是坏的:它用 + * `dict(zip(ids, display_ids))` 把「dict 键顺序」和「查询返回顺序」硬凑成对, + * 题目一旦被隐藏或删除,display_ids 就比 ids 短 —— 轻则把编号张冠李戴写进库, + * 重则 `id_map[k]` KeyError。这里改成按 id 建 Map、查不到就不动。 + */ accountRoutes.post("/me/problem-display-ids/refresh", requireAuth, async (c) => { const user = c.get("user")! const [profile] = await db.select({ value: schema.userProfile.acmProblemsStatus }).from(schema.userProfile) diff --git a/apps/web/src/oj/api.ts b/apps/web/src/oj/api.ts index 1c32095..c1cbeef 100644 --- a/apps/web/src/oj/api.ts +++ b/apps/web/src/oj/api.ts @@ -300,11 +300,6 @@ export function setReaction(problemID: number, type: ReactionKey) { return api2.post(`problems/${problemID}/reaction`, { type }) } -// TODO: 这个API有问题 -export function refreshUserProblemDisplayIds() { - return api2.post("me/problem-display-ids/refresh") -} - export function getMetrics(userid: number) { return api2.get(`users/${userid}/metrics`) }