manual matching survives ttl now
This commit is contained in:
@@ -363,20 +363,42 @@ async function fetchBookMetadata(id: string): Promise<Book | null> {
|
||||
}
|
||||
|
||||
async function searchChaptersInExtension(ext: Extension, name: string, lookupId: string, cacheId: string, search: boolean, origin: string, disableCache = false): Promise<ChapterWithProvider[]> {
|
||||
const cacheKey = `chapters:${name}:${origin}:${search ? "search" : "id"}:${cacheId}`;
|
||||
const cacheKey = `chapters:${name}:${origin}:id:${cacheId}`;
|
||||
if (!disableCache) {
|
||||
const cached = await getCache(cacheKey);
|
||||
|
||||
if (cached) {
|
||||
const isExpired = Date.now() - cached.created_at > CACHE_TTL_MS;
|
||||
|
||||
if (!isExpired) {
|
||||
console.log(`[${name}] Chapters cache hit for: ${lookupId}`);
|
||||
try {
|
||||
return JSON.parse(cached.result) as ChapterWithProvider[];
|
||||
} catch (e) {
|
||||
console.error(`[${name}] Error parsing cached chapters:`, e);
|
||||
try {
|
||||
const parsed = JSON.parse(cached.result) as {
|
||||
mediaId?: string;
|
||||
chapters: ChapterWithProvider[];
|
||||
};
|
||||
|
||||
if (!isExpired) {
|
||||
console.log(`[${name}] Chapters cache hit for: ${lookupId}`);
|
||||
return parsed.chapters;
|
||||
}
|
||||
|
||||
if (parsed.mediaId) {
|
||||
const chaps = await ext.findChapters!(parsed.mediaId);
|
||||
|
||||
const result = chaps.map(ch => ({
|
||||
id: ch.id,
|
||||
number: parseFloat(ch.number.toString()),
|
||||
title: ch.title,
|
||||
date: ch.releaseDate,
|
||||
provider: name,
|
||||
index: ch.index,
|
||||
language: ch.language ?? null,
|
||||
}));
|
||||
|
||||
await setCache(cacheKey, { mediaId: parsed.mediaId, chapters: result }, CACHE_TTL_MS);
|
||||
return result;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(`[${name}] Error parsing cached chapters:`, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -436,7 +458,10 @@ async function searchChaptersInExtension(ext: Extension, name: string, lookupId:
|
||||
language: ch.language ?? null,
|
||||
}));
|
||||
|
||||
await setCache(cacheKey, result, CACHE_TTL_MS);
|
||||
await setCache(cacheKey, {
|
||||
mediaId,
|
||||
chapters: result
|
||||
}, CACHE_TTL_MS);
|
||||
return result;
|
||||
|
||||
} catch (e) {
|
||||
|
||||
Reference in New Issue
Block a user