feat(后台): 补回「最高票评价」列,重写时漏掉了
管理端题目列表的「反馈」列一直是空的:前端渲染逻辑还在,后端两处 硬编码 topReaction: null —— 旧后端的 reaction/services.py:get_top_reactions 没有跟着迁过来,阶段 0 的清单也没抓到。 新增 services/reaction.ts,口径逐条对齐旧实现: - 按 (problem_id, type) 分组计数,取票数最高的那个; - 并列时按 reactionKeySchema 的定义顺序取靠前的,与前端 REACTIONS 的顺序 一致(旧后端是 TYPE_ORDER,已核对两边七个 key 的顺序与内容完全相同); - 只返回有评价的题目,没有的题调用方兜 null。 比库里可能残留、但前端已经下掉的类型多了一道跳过:不跳的话一个不再展示的 类型会以并列最优的身份把真正的最高票挤掉。 只有公开题列表下发,比赛题列表不下发 —— 与旧后端一致(旧的 top_reaction 只出现在 ProblemAPI,ContestProblemAPI 没有),前端那一列的注释也是这么写的。 实测:造 3 票 learned + 1 票 too_easy 取到 learned/3;interesting 与 too_hard 各 1 票时取到 too_hard(定义顺序在前);插一条 obsolete_kind 不影响结果;无评价的题返回 null。探针数据已清理。 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -26,6 +26,7 @@ import { packTestCaseZip, processTestCaseZip, readInfo, readSqlScripts, TestCase
|
||||
import { config } from "../../config"
|
||||
import { readFile } from "node:fs/promises"
|
||||
import { resolve } from "node:path"
|
||||
import { getTopReactions } from "../../services/reaction"
|
||||
import { objectValue, queryInteger, sampleUser, stringArray } from "../helpers"
|
||||
|
||||
export const adminProblemRoutes = new Hono<AppEnv>()
|
||||
@@ -252,6 +253,8 @@ adminProblemRoutes.get("/problems", requireProblemPermission, async (c) => {
|
||||
.leftJoin(schema.userProfile, eq(schema.userProfile.userId, schema.user.id))
|
||||
.where(where).orderBy(desc(schema.problem.createTime)).limit(limit).offset(offset),
|
||||
])
|
||||
// 只有公开题列表下发最高票评价,比赛题列表不下发 —— 与旧后端一致
|
||||
const topReactions = await getTopReactions(rows.map(({ problem }) => problem.id))
|
||||
return success(c, adminProblemListSchema.parse({
|
||||
results: await Promise.all(rows.map(async ({ problem, user: creator, realName }) =>
|
||||
adminProblemListItemSchema.parse({
|
||||
@@ -266,7 +269,7 @@ adminProblemRoutes.get("/problems", requireProblemPermission, async (c) => {
|
||||
hasAstRules: problem.astRules !== null,
|
||||
allowFlowchart: problem.allowFlowchart,
|
||||
showFlowchart: problem.showFlowchart,
|
||||
topReaction: null,
|
||||
topReaction: topReactions.get(problem.id) ?? null,
|
||||
}))),
|
||||
total: totalRow[0]?.value ?? 0,
|
||||
}))
|
||||
|
||||
Reference in New Issue
Block a user