fix(questions): 完成 questions/data-access.ts 遗漏的 cacheFn 迁移

This commit is contained in:
SpecialX
2026-07-05 22:27:07 +08:00
parent 841b130f4c
commit 0f33484bd2

View File

@@ -492,8 +492,9 @@ export type QuestionContentForErrorCollection = {
type: string type: string
} }
export const getQuestionsContentForErrorCollection = cache( export const getQuestionsContentForErrorCollectionRaw = async (
async (questionIds: string[]): Promise<Map<string, QuestionContentForErrorCollection>> => { questionIds: string[],
): Promise<Map<string, QuestionContentForErrorCollection>> => {
const result = new Map<string, QuestionContentForErrorCollection>() const result = new Map<string, QuestionContentForErrorCollection>()
const uniqueIds = Array.from(new Set(questionIds.filter((v): v is string => typeof v === "string" && v.length > 0))) const uniqueIds = Array.from(new Set(questionIds.filter((v): v is string => typeof v === "string" && v.length > 0)))
if (uniqueIds.length === 0) return result if (uniqueIds.length === 0) return result
@@ -512,6 +513,13 @@ export const getQuestionsContentForErrorCollection = cache(
} }
return result return result
} }
export const getQuestionsContentForErrorCollection = cacheFn(
getQuestionsContentForErrorCollectionRaw,
{
tags: ["questions"],
ttl: 300,
keyParts: ["questions", "getQuestionsContentForErrorCollection"],
},
) )
/** /**
@@ -522,8 +530,9 @@ export const getQuestionsContentForErrorCollection = cache(
* *
* 返回 Map<questionId, type>,未找到的 ID 不会出现在 Map 中。 * 返回 Map<questionId, type>,未找到的 ID 不会出现在 Map 中。
*/ */
export const getQuestionTypeMapByIds = cache( export const getQuestionTypeMapByIdsRaw = async (
async (questionIds: string[]): Promise<Map<string, string>> => { questionIds: string[],
): Promise<Map<string, string>> => {
const result = new Map<string, string>() const result = new Map<string, string>()
const uniqueIds = Array.from(new Set(questionIds.filter((v): v is string => typeof v === "string" && v.length > 0))) const uniqueIds = Array.from(new Set(questionIds.filter((v): v is string => typeof v === "string" && v.length > 0)))
if (uniqueIds.length === 0) return result if (uniqueIds.length === 0) return result
@@ -538,7 +547,11 @@ export const getQuestionTypeMapByIds = cache(
} }
return result return result
} }
) export const getQuestionTypeMapByIds = cacheFn(getQuestionTypeMapByIdsRaw, {
tags: ["questions"],
ttl: 300,
keyParts: ["questions", "getQuestionTypeMapByIds"],
})
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// 导入/导出接口 // 导入/导出接口