fix(题目列表): 排序里多了个用不上的「按题号」,原来的最早创建、最多 / 最少提交、通过都没了——换回原来那一套
Deploy / deploy (push) Canceled after 0s

最新创建 / 最早创建 / 最多人做过 / 最少人做过 / 最多人做对 / 最少人做对。排序值和原来一样,
旧链接照样能用;「最多 / 最少」改成按人数,和最后一列「做对 / 做过」对得上。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
xuyueandClaude Opus 5.5 committed 2026-10-09 12:58:26 +08:00
1 parent 97426f0895
commit e852bf4498
3 files changed
+33 -23

No files matched your search

+15 -18
View File
@@ -121,12 +121,6 @@ function listItem(
} satisfies ProblemListItem
}
/** 题号排序:先按长度再按字面,1001 < 1100 < P026 < SQL09,不会排成 1001、1100、11、2 */
const displayIdOrder = [
asc(sql`length(${schema.problem.displayId})`),
asc(schema.problem.displayId),
]
problemRoutes.get("/problems", optionalAuth, async (c) => {
const user = c.get("user")
const limit = queryInteger(c.req.query("limit"), 20, { min: 1, max: 250 })
@@ -169,23 +163,26 @@ problemRoutes.get("/problems", optionalAuth, async (c) => {
filters.push(notInArray(schema.problem.id, [...states.solved]))
const where = and(...filters)
// 默认按最新创建(选了知识点也一样)。旧的排序值(最多提交、画流程图……)落到默认 ——
// 类型已经拆成了单独的筛选
// 排序值沿用原来的(地址栏里存着的旧链接照样能用),但「最多 / 最少」现在按**人数**排,
// 和列表最后一列「做对 / 做过」对得上:submission_number 是做过的人,accepted_number 是做对的人。
// 旧的「画流程图 / 语法检查」排序已经拆成类型筛选,传进来落到默认(最新创建)
const sort = problemListSortSchema.safeParse(c.req.query("sort") ?? "").data ?? ""
const effective = sort || "new"
const allCounts = effective === "popular" ? await problemUserCounts() : null
const popularity = allCounts
const byPeople = sort.endsWith("submission_number") || sort.endsWith("accepted_number")
const allCounts = byPeople ? await problemUserCounts() : null
const people = allCounts
? sql`case ${schema.problem.id} ${sql.join(
[...allCounts].map(([id, n]) => sql`when ${id} then ${n.solved}`),
[...allCounts].map(
([id, n]) =>
sql`when ${id} then ${sort.endsWith("accepted_number") ? n.solved : n.tried}`,
),
sql` `,
)} else 0 end`
: null
const order =
effective === "id"
? displayIdOrder
: popularity
? [desc(popularity), ...displayIdOrder]
: [desc(schema.problem.createTime)]
const order = people
? [sort.startsWith("-") ? desc(people) : asc(people), desc(schema.problem.createTime)]
: sort === "create_time"
? [asc(schema.problem.createTime)]
: [desc(schema.problem.createTime)]
const [totalRow] = await db
.select({ value: countDistinct(schema.problem.id) })
.from(schema.problem)