chore(账号): 删掉没人调的 refreshUserProblemDisplayIds
Some checks failed
Deploy / deploy (push) Has been cancelled
Some checks failed
Deploy / deploy (push) Has been cancelled
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 <noreply@anthropic.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -300,11 +300,6 @@ export function setReaction(problemID: number, type: ReactionKey) {
|
||||
return api2.post<ReactionState>(`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<Metrics>(`users/${userid}/metrics`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user