fix(data-access): 修复 tsc 错误 + 完成 adaptive-practice/elective 迁移至 cacheFn

This commit is contained in:
SpecialX
2026-07-05 22:24:56 +08:00
parent 27374d1b2c
commit 841b130f4c
8 changed files with 320 additions and 136 deletions

View File

@@ -1,6 +1,5 @@
import "server-only"
import { cache } from "react"
import { createId } from "@paralleldrive/cuid2"
import { and, desc, eq, inArray, sql, type SQL } from "drizzle-orm"
@@ -101,11 +100,24 @@ export const buildCourseSelect = () =>
.from(electiveCourses)
/**
* 缓存科目/年级选项(单次请求复用,避免高频访问时重复查询)。
* 使用 React `cache()` 在同一渲染周期内去重。
* 缓存科目/年级选项(带 TTL 与缓存标签,跨请求复用)。
*/
const getCachedSubjectOptions = cache(async () => getCourseDisplayResolver().getSubjectOptions())
const getCachedGradeOptions = cache(async () => getCourseDisplayResolver().getGradeOptions())
const getCachedSubjectOptions = cacheFn(
async () => getCourseDisplayResolver().getSubjectOptions(),
{
tags: ["elective"],
ttl: 300,
keyParts: ["elective", "getCachedSubjectOptions"],
},
)
const getCachedGradeOptions = cacheFn(
async () => getCourseDisplayResolver().getGradeOptions(),
{
tags: ["elective"],
ttl: 300,
keyParts: ["elective", "getCachedGradeOptions"],
},
)
export const resolveCourseDisplayNames = async (rows: CourseCoreRow[]): Promise<{
teacherNames: Map<string, string | null>