Skip to content

Commit 6d678fc

Browse files
chore: remove redis ttl for static quiz and qa caches (#265)
1 parent 1ad1d7f commit 6d678fc

5 files changed

Lines changed: 7 additions & 26 deletions

File tree

frontend/components/q&a/AIWordHelper.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,6 @@ export default function AIWordHelper({
303303

304304
if (isOpen) {
305305
document.addEventListener('keydown', handleKeyDown);
306-
// Calculate scrollbar width and add padding to prevent layout shift
307306
const scrollbarWidth =
308307
window.innerWidth - document.documentElement.clientWidth;
309308
document.body.style.overflow = 'hidden';
@@ -582,14 +581,12 @@ export default function AIWordHelper({
582581
)}
583582
</button>
584583

585-
{/* Activity suggestions while waiting */}
586584
<div className="mt-4 w-full border-t border-gray-200 pt-4 dark:border-neutral-700">
587585
<p className="mb-3 text-center text-xs font-medium text-gray-500 dark:text-gray-400">
588586
{messages.rateLimit.whileWaiting}
589587
</p>
590588

591589
{rateLimitState.retryAttempts < 3 ? (
592-
// First suggestions: Take Quiz & Star GitHub
593590
<div className="flex flex-col gap-2">
594591
<Link
595592
href="/quizzes"
@@ -640,7 +637,6 @@ export default function AIWordHelper({
640637
</a>
641638
</div>
642639
) : (
643-
// After 3+ attempts: Sponsor & Review
644640
<div className="flex flex-col gap-2">
645641
<a
646642
href="https://github.com/sponsors/DevLoversTeam"

frontend/components/q&a/SelectableText.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export default function SelectableText({
1919
const onTextSelectRef = useRef(onTextSelect);
2020
const onSelectionClearRef = useRef(onSelectionClear);
2121

22-
// Keep refs updated with latest callbacks
2322
useEffect(() => {
2423
onTextSelectRef.current = onTextSelect;
2524
onSelectionClearRef.current = onSelectionClear;

frontend/lib/cache/qa.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { getRedisClient } from '@/lib/redis';
22

3-
const QA_CACHE_TTL_SECONDS = 60 * 60 * 12;
4-
53
type QaCacheKeyInput = {
64
category: string;
75
locale: string;
@@ -48,7 +46,7 @@ export async function setQaCache<T>(key: string, value: T) {
4846
const redis = getRedisClient();
4947
if (!redis) return;
5048

51-
await redis.set(key, value, { ex: QA_CACHE_TTL_SECONDS });
49+
await redis.set(key, value);
5250
}
5351

5452
export async function invalidateQaCacheByCategory(category: string) {
@@ -97,7 +95,3 @@ export async function invalidateAllQaCache() {
9795

9896
return deleted;
9997
}
100-
101-
export const qaCacheConfig = {
102-
ttlSeconds: QA_CACHE_TTL_SECONDS,
103-
};

frontend/lib/quiz/quiz-answers-redis.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@ import { db } from '@/db';
44
import { quizAnswers, quizQuestions } from '@/db/schema/quiz';
55
import { getRedisClient } from '@/lib/redis';
66

7-
const QUIZ_CACHE_TTL_SECONDS = 60 * 60 * 12;
8-
97
interface QuizAnswersCache {
108
quizId: string;
11-
answers: Record<string, string>; // questionId - correctAnswerId
9+
answers: Record<string, string>;
1210
cachedAt: number;
1311
}
1412

@@ -22,18 +20,16 @@ export async function getOrCreateQuizAnswersCache(
2220
const redis = getRedisClient();
2321
if (!redis) {
2422
console.warn('Redis not configured, skipping cache');
25-
return true; // Allow quiz to proceed without cache
23+
return true;
2624
}
2725

2826
const key = getCacheKey(quizId);
2927

30-
// Check if cache exists
3128
const existing = await redis.get<QuizAnswersCache>(key);
3229
if (existing) {
33-
return true; // Cache hit
30+
return true;
3431
}
3532

36-
// Fetch correct answers from DB
3733
const correctAnswers = await db
3834
.select({
3935
questionId: quizQuestions.id,
@@ -60,7 +56,7 @@ export async function getOrCreateQuizAnswersCache(
6056
cachedAt: Date.now(),
6157
};
6258

63-
await redis.set(key, cacheData, { ex: QUIZ_CACHE_TTL_SECONDS });
59+
await redis.set(key, cacheData);
6460
return true;
6561
}
6662

@@ -69,7 +65,7 @@ export async function getCorrectAnswer(
6965
questionId: string
7066
): Promise<string | null> {
7167
const redis = getRedisClient();
72-
68+
7369
if (redis) {
7470
const key = getCacheKey(quizId);
7571
const cache = await redis.get<QuizAnswersCache>(key);
@@ -78,7 +74,6 @@ export async function getCorrectAnswer(
7874
}
7975
}
8076

81-
// DB fallback when Redis unavailable or cache miss
8277
const result = await db
8378
.select({ answerId: quizAnswers.id })
8479
.from(quizAnswers)
@@ -94,4 +89,3 @@ export async function getCorrectAnswer(
9489

9590
return result[0]?.answerId ?? null;
9691
}
97-

frontend/lib/quiz/quiz-session.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const STORAGE_KEY_PREFIX = 'quiz_session_';
2-
const SESSION_TTL_MS = 30 * 60 * 1000; // 30 minutes
2+
const SESSION_TTL_MS = 30 * 60 * 1000;
33

44
export interface QuizSessionData {
55
status: 'rules' | 'in_progress' | 'completed';
@@ -39,13 +39,11 @@ export function loadQuizSession(quizId: string): QuizSessionData | null {
3939

4040
const data: QuizSessionData = JSON.parse(raw);
4141

42-
// Discard sessions older than 30 minutes
4342
if (Date.now() - data.savedAt > SESSION_TTL_MS) {
4443
clearQuizSession(quizId);
4544
return null;
4645
}
4746

48-
// Only restore in_progress sessions
4947
if (data.status === 'rules') {
5048
clearQuizSession(quizId);
5149
return null;

0 commit comments

Comments
 (0)