fix: xREL Cache-Logik sauber – Suchen lädt frisch, Reload zeigt Cache, Aktualisieren refresht
This commit is contained in:
@@ -250,16 +250,17 @@ 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';
|
||||||
|
|
||||||
// Cache-Verhalten:
|
|
||||||
// - Befüllte Einträge: immer sofort zurückgeben (auch bei refresh=1)
|
|
||||||
// - Leere Einträge: ignorieren, frisch suchen
|
|
||||||
const cached = cacheGet(cacheKey);
|
|
||||||
if (cached !== undefined && cached.length > 0) {
|
|
||||||
return res.json({ xrel: cached, has_xrel: true });
|
|
||||||
}
|
|
||||||
// Bei refresh=1: leeren Cache-Eintrag löschen damit neu gesucht wird
|
|
||||||
if (forceRefresh) {
|
if (forceRefresh) {
|
||||||
|
// Aktualisieren: Cache löschen und frisch von xREL laden
|
||||||
db.prepare('DELETE FROM xrel_cache WHERE cache_key=?').run(cacheKey);
|
db.prepare('DELETE FROM xrel_cache WHERE cache_key=?').run(cacheKey);
|
||||||
|
} else {
|
||||||
|
// Normaler Aufruf: befüllten Cache zurückgeben, bei leerem → nichts zurückgeben
|
||||||
|
const cached = cacheGet(cacheKey);
|
||||||
|
if (cached !== undefined) {
|
||||||
|
return res.json({ xrel: cached, has_xrel: cached.length > 0 });
|
||||||
|
}
|
||||||
|
// Kein Cache: auch kein xREL-Call, nur leeres Ergebnis
|
||||||
|
return res.json({ xrel: [], has_xrel: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Titel + IMDb-ID aus Query-Params wenn vorhanden (spart 2 TMDb-Calls)
|
// Titel + IMDb-ID aus Query-Params wenn vorhanden (spart 2 TMDb-Calls)
|
||||||
|
|||||||
@@ -467,23 +467,25 @@ function MovieModal({ tmdbId, onClose, mobile, onHasXrel }) {
|
|||||||
api(`/tools/media/movie/${tmdbId}`)
|
api(`/tools/media/movie/${tmdbId}`)
|
||||||
.then(d => { setDetail(d); setLoading(false); })
|
.then(d => { setDetail(d); setLoading(false); })
|
||||||
.catch(e => { setError(e.message); setLoading(false); });
|
.catch(e => { setError(e.message); setLoading(false); });
|
||||||
|
// Gecachte Releases laden – ohne refresh, nur befüllte Einträge
|
||||||
|
api(`/tools/media/movie/${tmdbId}/xrel`)
|
||||||
|
.then(d => { if (d.xrel?.length > 0) { setXrel(d.xrel); onHasXrel?.(tmdbId); } })
|
||||||
|
.catch(() => {});
|
||||||
const prev = document.body.style.overflow;
|
const prev = document.body.style.overflow;
|
||||||
document.body.style.overflow = 'hidden';
|
document.body.style.overflow = 'hidden';
|
||||||
return () => { document.body.style.overflow = prev; };
|
return () => { document.body.style.overflow = prev; };
|
||||||
}, [tmdbId]);
|
}, [tmdbId]);
|
||||||
|
|
||||||
const searchXrel = async () => {
|
const searchXrel = async (forceRefresh = false) => {
|
||||||
if (!detail) return;
|
if (!detail) return;
|
||||||
setXrelLoading(true);
|
setXrelLoading(true);
|
||||||
try {
|
try {
|
||||||
// Immer refresh=1: ignoriert leere Cache-Einträge, sucht frisch
|
|
||||||
// Befüllte Cache-Einträge werden trotzdem sofort zurückgegeben (Backend-Logik)
|
|
||||||
const params = new URLSearchParams({
|
const params = new URLSearchParams({
|
||||||
title: detail.title || '',
|
title: detail.title || '',
|
||||||
orig: detail.original_title || '',
|
orig: detail.original_title || '',
|
||||||
imdb_id: detail.imdb_id || '',
|
imdb_id: detail.imdb_id || '',
|
||||||
refresh: '1',
|
|
||||||
});
|
});
|
||||||
|
if (forceRefresh) params.set('refresh', '1');
|
||||||
const d = await api(`/tools/media/movie/${tmdbId}/xrel?${params}`);
|
const d = await api(`/tools/media/movie/${tmdbId}/xrel?${params}`);
|
||||||
setXrel(d.xrel || []);
|
setXrel(d.xrel || []);
|
||||||
if (d.has_xrel) onHasXrel?.(tmdbId);
|
if (d.has_xrel) onHasXrel?.(tmdbId);
|
||||||
@@ -629,7 +631,7 @@ function MovieModal({ tmdbId, onClose, mobile, onHasXrel }) {
|
|||||||
<div style={{ display:'flex', alignItems:'center', gap:8, marginBottom: xrel?.length ? 8 : 0 }}>
|
<div style={{ display:'flex', alignItems:'center', gap:8, marginBottom: xrel?.length ? 8 : 0 }}>
|
||||||
<div style={{ ...S.head, marginBottom:0, flex:1 }}>RELEASES (XREL.TO)</div>
|
<div style={{ ...S.head, marginBottom:0, flex:1 }}>RELEASES (XREL.TO)</div>
|
||||||
<button
|
<button
|
||||||
onClick={() => searchXrel()}
|
onClick={() => searchXrel(xrel !== null && xrel.length > 0)}
|
||||||
disabled={xrelLoading}
|
disabled={xrelLoading}
|
||||||
style={{
|
style={{
|
||||||
fontSize:10, fontFamily:'monospace', cursor: xrelLoading ? 'default' : 'pointer',
|
fontSize:10, fontFamily:'monospace', cursor: xrelLoading ? 'default' : 'pointer',
|
||||||
|
|||||||
Reference in New Issue
Block a user