fix: xREL immer suchen wenn kein befüllter Cache, Titel-Match vereinfacht

This commit is contained in:
2026-06-11 09:36:55 +02:00
parent cc38347363
commit 5941cc26d8

View File

@@ -159,26 +159,18 @@ async function getXrelData(tmdbId, imdbId, title, originalTitle) {
} }
} }
// Strategie 2: Exakter Titel-Match // Strategie 2: Titel/alt_title Match gegen alle Queries (normalisiert)
if (!extInfoId) { if (!extInfoId) {
const allCleanQueries = allQueries.map(q => clean(q));
for (const r of searchResults) { for (const r of searchResults) {
if (!r) continue; if (!r?.data?.results) continue;
const hit = (r.data?.results||[]).find(h => for (const h of r.data.results) {
clean(h.title) === clean(r.q) || clean(h.alt_title) === clean(r.q) if (allCleanQueries.includes(clean(h.title)) || allCleanQueries.includes(clean(h.alt_title))) {
); extInfoId = h.id;
if (hit?.id) { extInfoId = hit.id; break; } break;
} }
}
// Strategie 3: Einziger Treffer bei IMDb-Suche (nur wenn exakt 1 Ergebnis)
if (!extInfoId && imdbId) {
for (const r of searchResults) {
if (!r) continue;
const results = r.data?.results || [];
if (results.length === 1 && results[0].type === 'movie') {
extInfoId = results[0].id;
break;
} }
if (extInfoId) break;
} }
} }
@@ -286,18 +278,19 @@ router.get('/movie/:id/xrel', authenticate, async (req, res) => {
const cacheKey = `xrel:tmdb:${req.params.id}`; const cacheKey = `xrel:tmdb:${req.params.id}`;
const forceRefresh = req.query.refresh === '1'; const forceRefresh = req.query.refresh === '1';
if (forceRefresh) { // Cache prüfen: befüllte Einträge immer zurückgeben
// Aktualisieren: Cache löschen und frisch von xREL laden // Bei refresh=1 oder leerem Cache: xREL aufrufen
db.prepare('DELETE FROM xrel_cache WHERE cache_key=?').run(cacheKey); if (!forceRefresh) {
} else {
// Normaler Aufruf: befüllten Cache zurückgeben, bei leerem → nichts zurückgeben
const cached = cacheGet(cacheKey); const cached = cacheGet(cacheKey);
if (cached !== undefined) { if (cached !== undefined && cached.length > 0) {
return res.json({ xrel: cached, has_xrel: cached.length > 0 }); return res.json({ xrel: cached, has_xrel: true });
} }
// Kein Cache: auch kein xREL-Call, nur leeres Ergebnis
return res.json({ xrel: [], has_xrel: false });
} }
// Cache löschen bei refresh (damit neu gecacht wird)
if (forceRefresh) {
db.prepare('DELETE FROM xrel_cache WHERE cache_key=?').run(cacheKey);
}
// Immer xREL aufrufen wenn kein befüllter Cache
// Titel + IMDb-ID aus Query-Params wenn vorhanden (spart 2 TMDb-Calls) // Titel + IMDb-ID aus Query-Params wenn vorhanden (spart 2 TMDb-Calls)
let imdbId = req.query.imdb_id || null; let imdbId = req.query.imdb_id || null;