From 5941cc26d851eb44fbb92d9e103a69b92c6f884a Mon Sep 17 00:00:00 2001 From: Dicken Date: Thu, 11 Jun 2026 09:36:55 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20xREL=20immer=20suchen=20wenn=20kein=20be?= =?UTF-8?q?f=C3=BCllter=20Cache,=20Titel-Match=20vereinfacht?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/tools/media/routes.js | 45 +++++++++++++------------------ 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/backend/src/tools/media/routes.js b/backend/src/tools/media/routes.js index 60ec314..51b5ef9 100644 --- a/backend/src/tools/media/routes.js +++ b/backend/src/tools/media/routes.js @@ -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) { + const allCleanQueries = allQueries.map(q => clean(q)); for (const r of searchResults) { - if (!r) continue; - const hit = (r.data?.results||[]).find(h => - clean(h.title) === clean(r.q) || clean(h.alt_title) === clean(r.q) - ); - if (hit?.id) { extInfoId = hit.id; 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 (!r?.data?.results) continue; + for (const h of r.data.results) { + if (allCleanQueries.includes(clean(h.title)) || allCleanQueries.includes(clean(h.alt_title))) { + extInfoId = h.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 forceRefresh = req.query.refresh === '1'; - if (forceRefresh) { - // Aktualisieren: Cache löschen und frisch von xREL laden - db.prepare('DELETE FROM xrel_cache WHERE cache_key=?').run(cacheKey); - } else { - // Normaler Aufruf: befüllten Cache zurückgeben, bei leerem → nichts zurückgeben + // Cache prüfen: befüllte Einträge immer zurückgeben + // Bei refresh=1 oder leerem Cache: xREL aufrufen + if (!forceRefresh) { const cached = cacheGet(cacheKey); - if (cached !== undefined) { - return res.json({ xrel: cached, has_xrel: cached.length > 0 }); + if (cached !== undefined && 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) let imdbId = req.query.imdb_id || null;