Cache LRU sur entry endpoints (movie/tv/imdb/providers) + allowlist loopback du rate limit

This commit is contained in:
unfr
2026-05-10 01:14:33 +02:00
parent 8247544d1b
commit 92005a9cbe
4 changed files with 33 additions and 6 deletions

View File

@@ -20,19 +20,36 @@ import { filterAndLower } from '../lib/titleFilter.js';
const searchCache = new LRUCache({ max: 1000, ttl: 1000 * 60 * 60 });
// Entry cache covers movie/tv/imdb/providers responses. Keeps hot files in RAM
// so repeat lookups skip disk + JSON.parse. TTL 30 min (cron may rewrite
// underlying detail file via /changes — 30 min keeps staleness bounded).
const entryCache = new LRUCache({ max: 5000, ttl: 1000 * 60 * 30 });
async function getDetail(type, id) {
const key = `d:${type}:${id}`;
const hit = entryCache.get(key);
if (hit !== undefined) return hit;
try {
const buf = await readFile(entryPath(type, id), 'utf8');
return JSON.parse(buf);
const obj = JSON.parse(buf);
entryCache.set(key, obj);
return obj;
} catch {
entryCache.set(key, null);
return null;
}
}
async function getProviders(type, id) {
const key = `p:${type}:${id}`;
const hit = entryCache.get(key);
if (hit !== undefined) return hit;
try {
return JSON.parse(await readFile(justwatchPath(type, id), 'utf8'));
const obj = JSON.parse(await readFile(justwatchPath(type, id), 'utf8'));
entryCache.set(key, obj);
return obj;
} catch {
entryCache.set(key, null);
return null;
}
}