fix
This commit is contained in:
@@ -192,8 +192,12 @@ async function getOrGenerateTopicQuestions(topic, count) {
|
||||
let bank = await db.getQuizBank(topic.id);
|
||||
|
||||
if (bank.length < count) {
|
||||
try {
|
||||
await forceGenerateTopicQuestions(topic, 5);
|
||||
bank = await db.getQuizBank(topic.id);
|
||||
} catch (err) {
|
||||
console.warn(`[quiz] Failed to generate questions for ${topic.label}:`, err.message);
|
||||
}
|
||||
}
|
||||
|
||||
return sample(bank, Math.min(count, bank.length));
|
||||
@@ -210,7 +214,7 @@ export async function deleteQuestion(topicId, questionId) {
|
||||
export async function generateWeeklyQuiz(userId, weekNumber, force = false) {
|
||||
if (!force) {
|
||||
const cached = await db.getCachedQuiz(userId, weekNumber);
|
||||
if (cached) return cached;
|
||||
if (cached?.questions?.length > 0) return cached;
|
||||
}
|
||||
|
||||
const { primaryTopic, reviewTopics } = await selectTestTopics(userId, weekNumber);
|
||||
@@ -240,6 +244,10 @@ export async function generateWeeklyQuiz(userId, weekNumber, force = false) {
|
||||
|
||||
const shuffled = shuffle(questions).slice(0, 5);
|
||||
|
||||
if (shuffled.length === 0) {
|
||||
throw new Error('Could not assemble enough questions for this week\'s test. Please try again.');
|
||||
}
|
||||
|
||||
const quiz = {
|
||||
questions: shuffled,
|
||||
meta: {
|
||||
|
||||
@@ -15,6 +15,9 @@ function getBuildSha() {
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
build: {
|
||||
sourcemap: true,
|
||||
},
|
||||
define: {
|
||||
__BUILD_SHA__: JSON.stringify(getBuildSha()),
|
||||
__BUILD_TIME__: JSON.stringify(new Date().toISOString()),
|
||||
|
||||
Reference in New Issue
Block a user