refactor(data-access): 补全剩余 37 个 data-access 文件迁移至 cacheFn
迁移范围:lesson-preparation 11 文件、attendance 3 文件、settings 4 文件、classes-invitations、跨模块接口 4 文件、adaptive-practice/ai/onboarding/invitation-codes/search/standards/scheduling/leave-requests/audit。修复 3 个 cacheFn 块位置错误。同步架构文档迁移范围至 83 文件 250+ 函数。
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import "server-only"
|
||||
|
||||
import { cache } from "react"
|
||||
import { cacheFn } from "@/shared/lib/cache"
|
||||
import { and, desc, eq, inArray } from "drizzle-orm"
|
||||
|
||||
import { db } from "@/shared/db"
|
||||
@@ -33,7 +33,7 @@ import type {
|
||||
} from "./types"
|
||||
|
||||
/** 获取学生在所有知识点的掌握度(含知识点名称) */
|
||||
const getStudentMastery = cache(async (studentId: string): Promise<MasteryWithKnowledgePoint[]> => {
|
||||
const getStudentMasteryRaw = async (studentId: string): Promise<MasteryWithKnowledgePoint[]> => {
|
||||
const rows = await db
|
||||
.select({
|
||||
mastery: knowledgePointMastery,
|
||||
@@ -52,10 +52,16 @@ const getStudentMastery = cache(async (studentId: string): Promise<MasteryWithKn
|
||||
kpDescription: r.kpDescription,
|
||||
} satisfies RawMasteryWithKpRow),
|
||||
)
|
||||
}
|
||||
|
||||
const getStudentMastery = cacheFn(getStudentMasteryRaw, {
|
||||
tags: ["diagnostic"],
|
||||
ttl: 300,
|
||||
keyParts: ["diagnostic", "getStudentMastery"],
|
||||
})
|
||||
|
||||
/** 获取学生掌握度摘要(含强项/弱项分析) */
|
||||
export const getStudentMasterySummary = cache(async (studentId: string): Promise<StudentMasterySummary | null> => {
|
||||
export const getStudentMasterySummaryRaw = async (studentId: string): Promise<StudentMasterySummary | null> => {
|
||||
// P3-18 修复:用户名查询与掌握度查询相互独立,并行执行
|
||||
const [userMap, allMastery] = await Promise.all([
|
||||
getUserNamesByIds([studentId]),
|
||||
@@ -65,6 +71,12 @@ export const getStudentMasterySummary = cache(async (studentId: string): Promise
|
||||
if (!student) return null
|
||||
|
||||
return buildStudentMasterySummary(studentId, student.name ?? "Unknown", allMastery)
|
||||
}
|
||||
|
||||
export const getStudentMasterySummary = cacheFn(getStudentMasterySummaryRaw, {
|
||||
tags: ["diagnostic"],
|
||||
ttl: 300,
|
||||
keyParts: ["diagnostic", "getStudentMasterySummary"],
|
||||
})
|
||||
|
||||
/** 从提交答案更新掌握度(累积模式:在历史基础上累加,正确率作为掌握度) */
|
||||
@@ -322,7 +334,7 @@ export async function updateMasteryFromExamScore(
|
||||
}
|
||||
|
||||
/** 获取班级掌握度摘要 */
|
||||
export const getClassMasterySummary = cache(async (classId: string): Promise<ClassMasterySummary | null> => {
|
||||
export const getClassMasterySummaryRaw = async (classId: string): Promise<ClassMasterySummary | null> => {
|
||||
const classExists = await getClassExists(classId)
|
||||
if (!classExists) return null
|
||||
|
||||
@@ -361,10 +373,16 @@ export const getClassMasterySummary = cache(async (classId: string): Promise<Cla
|
||||
}))
|
||||
|
||||
return buildClassMasterySummary(classId, className, students, rawRows)
|
||||
}
|
||||
|
||||
export const getClassMasterySummary = cacheFn(getClassMasterySummaryRaw, {
|
||||
tags: ["diagnostic"],
|
||||
ttl: 300,
|
||||
keyParts: ["diagnostic", "getClassMasterySummary"],
|
||||
})
|
||||
|
||||
/** v4-P2-3: 获取年级掌握度摘要 */
|
||||
export const getGradeMasterySummary = cache(async (gradeId: string): Promise<GradeMasterySummary | null> => {
|
||||
export const getGradeMasterySummaryRaw = async (gradeId: string): Promise<GradeMasterySummary | null> => {
|
||||
// 年级名称 与 学生列表 相互独立,并行拉取
|
||||
const [gradeNameResult, studentIds] = await Promise.all([
|
||||
getGradeNameById(gradeId),
|
||||
@@ -400,10 +418,16 @@ export const getGradeMasterySummary = cache(async (gradeId: string): Promise<Gra
|
||||
}))
|
||||
|
||||
return buildGradeMasterySummary(gradeId, gradeName, students, rawRows)
|
||||
}
|
||||
|
||||
export const getGradeMasterySummary = cacheFn(getGradeMasterySummaryRaw, {
|
||||
tags: ["diagnostic"],
|
||||
ttl: 300,
|
||||
keyParts: ["diagnostic", "getGradeMasterySummary"],
|
||||
})
|
||||
|
||||
/** 获取知识点统计(按班级或年级聚合) */
|
||||
export const getKnowledgePointStats = cache(async (classId?: string, gradeId?: string): Promise<KnowledgePointStat[]> => {
|
||||
export const getKnowledgePointStatsRaw = async (classId?: string, gradeId?: string): Promise<KnowledgePointStat[]> => {
|
||||
let studentIds: string[] = []
|
||||
if (classId) {
|
||||
studentIds = await getActiveStudentIdsByClassId(classId)
|
||||
@@ -430,6 +454,12 @@ export const getKnowledgePointStats = cache(async (classId?: string, gradeId?: s
|
||||
|
||||
const { byKp } = aggregateClassMastery(rawRows, studentIds)
|
||||
return computeKpStats(byKp)
|
||||
}
|
||||
|
||||
export const getKnowledgePointStats = cacheFn(getKnowledgePointStatsRaw, {
|
||||
tags: ["diagnostic"],
|
||||
ttl: 300,
|
||||
keyParts: ["diagnostic", "getKnowledgePointStats"],
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -439,8 +469,7 @@ export const getKnowledgePointStats = cache(async (classId?: string, gradeId?: s
|
||||
* 在该知识点上的掌握度,便于针对性辅导。掌握度低于阈值(默认 60)的学生
|
||||
* 排在前面并标记为"需关注"。
|
||||
*/
|
||||
export const getClassStudentsByKnowledgePoint = cache(
|
||||
async (
|
||||
export const getClassStudentsByKnowledgePointRaw = async (
|
||||
classId: string,
|
||||
knowledgePointId: string,
|
||||
options?: { threshold?: number }
|
||||
@@ -516,4 +545,9 @@ export const getClassStudentsByKnowledgePoint = cache(
|
||||
|
||||
return result
|
||||
}
|
||||
)
|
||||
|
||||
export const getClassStudentsByKnowledgePoint = cacheFn(getClassStudentsByKnowledgePointRaw, {
|
||||
tags: ["diagnostic"],
|
||||
ttl: 300,
|
||||
keyParts: ["diagnostic", "getClassStudentsByKnowledgePoint"],
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user