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,27 +159,19 @@ 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;
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;
}
}
if (!extInfoId) {
@@ -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;