@@ -4,8 +4,8 @@ import { cache } from 'react';
44
55import { getOrCreateQuestionsCache } from '@/lib/quiz/quiz-answers-redis' ;
66import type {
7- AttemptReview ,
87 AttemptQuestionDetail ,
8+ AttemptReview ,
99 QuizQuestionWithAnswers ,
1010 UserLastAttempt ,
1111} from '@/types/quiz' ;
@@ -22,14 +22,7 @@ import {
2222 quizTranslations ,
2323 quizzes ,
2424} from '../schema/quiz' ;
25- export type {
26- AttemptReview ,
27- AttemptQuestionDetail ,
28- QuizAnswer ,
29- QuizQuestion ,
30- QuizQuestionWithAnswers ,
31- UserLastAttempt ,
32- } from '@/types/quiz' ;
25+ export type { QuizAnswer , QuizQuestion , QuizQuestionWithAnswers } from '@/types/quiz' ;
3326
3427export interface Quiz {
3528 id : string ;
@@ -61,23 +54,25 @@ export interface QuizQuestionClient {
6154
6255const attemptReviewCache = new Map < string , AttemptReview > ( ) ;
6356
64- function getAttemptReviewCacheKey ( attemptId : string , locale : string ) {
65- return `${ attemptId } :${ locale } ` ;
57+ function getAttemptReviewCacheKey ( attemptId : string , userId : string , locale : string ) {
58+ return `${ attemptId } :${ userId } : ${ locale } ` ;
6659}
6760
6861async function getCachedAttemptReview (
6962 attemptId : string ,
63+ userId : string ,
7064 locale : string
7165) : Promise < AttemptReview | null > {
72- return attemptReviewCache . get ( getAttemptReviewCacheKey ( attemptId , locale ) ) ?? null ;
66+ return attemptReviewCache . get ( getAttemptReviewCacheKey ( attemptId , userId , locale ) ) ?? null ;
7367}
7468
7569async function cacheAttemptReview (
7670 attemptId : string ,
71+ userId : string ,
7772 locale : string ,
7873 review : AttemptReview
7974) : Promise < void > {
80- attemptReviewCache . set ( getAttemptReviewCacheKey ( attemptId , locale ) , review ) ;
75+ attemptReviewCache . set ( getAttemptReviewCacheKey ( attemptId , userId , locale ) , review ) ;
8176}
8277
8378export function stripCorrectAnswers (
@@ -491,7 +486,7 @@ export async function getAttemptReviewDetails(
491486 userId : string ,
492487 locale : string = 'uk'
493488) : Promise < AttemptReview | null > {
494- const cached = await getCachedAttemptReview ( attemptId , locale ) ;
489+ const cached = await getCachedAttemptReview ( attemptId , userId , locale ) ;
495490 if ( cached ) return cached ;
496491
497492 const attemptRow = await db
@@ -552,7 +547,7 @@ export async function getAttemptReviewDetails(
552547 completedAt : attempt . completedAt ,
553548 incorrectQuestions : [ ] ,
554549 } ;
555- await cacheAttemptReview ( attemptId , locale , review ) ;
550+ await cacheAttemptReview ( attemptId , userId , locale , review ) ;
556551 return review ;
557552 }
558553
@@ -635,6 +630,6 @@ export async function getAttemptReviewDetails(
635630 incorrectQuestions,
636631 } ;
637632
638- await cacheAttemptReview ( attemptId , locale , review ) ;
633+ await cacheAttemptReview ( attemptId , userId , locale , review ) ;
639634 return review ;
640635}
0 commit comments