diff --git a/src/lib/api.ts b/src/lib/api.ts index 95c42c4..3d482f1 100644 --- a/src/lib/api.ts +++ b/src/lib/api.ts @@ -1,5 +1,4 @@ import type { Comic, Genre, ComicType } from './types'; -import { getRedisClient } from './db'; const languageMap = { "en": "English", @@ -178,11 +177,11 @@ export async function getComicBySlug(slug: string): Promise export async function getChaptersByHid( hid: string, slug: string, - params: ChapterParams = { limit: 5, lang: 'en' } + params: ChapterParams = { limit: 15, lang: 'en' } ): Promise { try { const queryParams = new URLSearchParams({ - limit: params.limit?.toString() || '5', + limit: params.limit?.toString() || '15', lang: params.lang || 'en', ordering: '-created_at' }); @@ -257,27 +256,9 @@ export async function getChaptersForSlugs( ): Promise { console.log(`Fetching chapters for slugs:`, slugs, `in language: ${lang}`); const chapters: ChapterDetail[] = []; - const redis = await getRedisClient(); - // Cache results for 1 hour (3600 seconds) - const CACHE_TTL = 60 * 60; - for (const slug of slugs) { console.log(`Processing slug: ${slug}`); - const cacheKey = `chapters:${slug}:${lang}`; - - try { - // Try to get cached chapters - const cachedChapters = await redis.get(cacheKey); - if (cachedChapters) { - console.log(`Using cached chapters for ${slug}`); - chapters.push(...JSON.parse(cachedChapters)); - continue; - } - } catch (error) { - console.error('Redis cache read error:', error); - } - const comicDetail = await getComicBySlug(slug); if (!comicDetail) { @@ -295,7 +276,7 @@ export async function getChaptersForSlugs( comicDetail.comic.hid, slug, { - limit: 5, + limit: 15, lang: lang } ); @@ -303,19 +284,6 @@ export async function getChaptersForSlugs( if (comicChapters.length > 0) { chapters.push(...comicChapters); - - // Cache the results - try { - await redis.set( - cacheKey, - JSON.stringify(comicChapters), - 'EX', - CACHE_TTL - ); - console.log(`Cached chapters for ${slug}`); - } catch (error) { - console.error('Redis cache write error:', error); - } } } diff --git a/src/lib/db.ts b/src/lib/db.ts index 90f6642..ffcc509 100644 --- a/src/lib/db.ts +++ b/src/lib/db.ts @@ -5,7 +5,6 @@ const REDIS_URL = import.meta.env.REDIS_URL || process.env.REDIS_URL; let redis: Redis | null = null; let redisRetryCount = 0; const MAX_RETRIES = 3; -const DEFAULT_CACHE_TTL = 60 * 60 * 24 * 30; // 30 days try { console.log('Environment check:', { @@ -61,7 +60,7 @@ try { } } -export async function getRedisClient(): Promise { +async function getRedisClient(): Promise { if (redis?.status === 'ready') return redis; if (redisRetryCount >= MAX_RETRIES) { @@ -110,7 +109,7 @@ export async function storeFeedMapping(feedId: string, slugs: string[], lang: st feedId, JSON.stringify(mapping), 'EX', - DEFAULT_CACHE_TTL + 60 * 60 * 24 * 30 // 30 days in seconds ); } catch (error) { console.error('Error storing feed mapping:', error); @@ -128,8 +127,6 @@ export async function getFeedMapping(feedId: string): Promise