fix(questions): 完成 questions/data-access.ts 遗漏的 cacheFn 迁移
This commit is contained in:
@@ -492,26 +492,34 @@ export type QuestionContentForErrorCollection = {
|
|||||||
type: string
|
type: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getQuestionsContentForErrorCollection = cache(
|
export const getQuestionsContentForErrorCollectionRaw = async (
|
||||||
async (questionIds: string[]): Promise<Map<string, QuestionContentForErrorCollection>> => {
|
questionIds: string[],
|
||||||
const result = new Map<string, QuestionContentForErrorCollection>()
|
): Promise<Map<string, QuestionContentForErrorCollection>> => {
|
||||||
const uniqueIds = Array.from(new Set(questionIds.filter((v): v is string => typeof v === "string" && v.length > 0)))
|
const result = new Map<string, QuestionContentForErrorCollection>()
|
||||||
if (uniqueIds.length === 0) return result
|
const uniqueIds = Array.from(new Set(questionIds.filter((v): v is string => typeof v === "string" && v.length > 0)))
|
||||||
|
if (uniqueIds.length === 0) return result
|
||||||
|
|
||||||
const rows = await db
|
const rows = await db
|
||||||
.select({
|
.select({
|
||||||
id: questions.id,
|
id: questions.id,
|
||||||
content: questions.content,
|
content: questions.content,
|
||||||
type: questions.type,
|
type: questions.type,
|
||||||
})
|
})
|
||||||
.from(questions)
|
.from(questions)
|
||||||
.where(inArray(questions.id, uniqueIds))
|
.where(inArray(questions.id, uniqueIds))
|
||||||
|
|
||||||
for (const r of rows) {
|
for (const r of rows) {
|
||||||
result.set(r.id, { content: r.content, type: r.type })
|
result.set(r.id, { content: r.content, type: r.type })
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
export const getQuestionsContentForErrorCollection = cacheFn(
|
||||||
|
getQuestionsContentForErrorCollectionRaw,
|
||||||
|
{
|
||||||
|
tags: ["questions"],
|
||||||
|
ttl: 300,
|
||||||
|
keyParts: ["questions", "getQuestionsContentForErrorCollection"],
|
||||||
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -522,23 +530,28 @@ 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[],
|
||||||
const result = new Map<string, string>()
|
): Promise<Map<string, string>> => {
|
||||||
const uniqueIds = Array.from(new Set(questionIds.filter((v): v is string => typeof v === "string" && v.length > 0)))
|
const result = new Map<string, string>()
|
||||||
if (uniqueIds.length === 0) return result
|
const uniqueIds = Array.from(new Set(questionIds.filter((v): v is string => typeof v === "string" && v.length > 0)))
|
||||||
|
if (uniqueIds.length === 0) return result
|
||||||
|
|
||||||
const rows = await db
|
const rows = await db
|
||||||
.select({ id: questions.id, type: questions.type })
|
.select({ id: questions.id, type: questions.type })
|
||||||
.from(questions)
|
.from(questions)
|
||||||
.where(inArray(questions.id, uniqueIds))
|
.where(inArray(questions.id, uniqueIds))
|
||||||
|
|
||||||
for (const r of rows) {
|
for (const r of rows) {
|
||||||
result.set(r.id, r.type)
|
result.set(r.id, r.type)
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
)
|
return result
|
||||||
|
}
|
||||||
|
export const getQuestionTypeMapByIds = cacheFn(getQuestionTypeMapByIdsRaw, {
|
||||||
|
tags: ["questions"],
|
||||||
|
ttl: 300,
|
||||||
|
keyParts: ["questions", "getQuestionTypeMapByIds"],
|
||||||
|
})
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// 导入/导出接口
|
// 导入/导出接口
|
||||||
|
|||||||
Reference in New Issue
Block a user