fix: kein Auto-Load im Modal, Button immer frisch suchen, Cache nur für befüllte Einträge
This commit is contained in:
@@ -250,14 +250,15 @@ router.get('/movie/:id/xrel', authenticate, async (req, res) => {
|
||||
const cacheKey = `xrel:tmdb:${req.params.id}`;
|
||||
const forceRefresh = req.query.refresh === '1';
|
||||
|
||||
if (!forceRefresh) {
|
||||
// Cache-Verhalten:
|
||||
// - Befüllte Einträge: immer sofort zurückgeben (auch bei refresh=1)
|
||||
// - Leere Einträge: ignorieren, frisch suchen
|
||||
const cached = cacheGet(cacheKey);
|
||||
// Nur nicht-leere Cache-Einträge sofort zurückgeben
|
||||
// Leere Einträge → nochmal suchen (könnte Rate-Limit-Artefakt sein)
|
||||
if (cached !== undefined && cached.length > 0) {
|
||||
return res.json({ xrel: cached, has_xrel: true });
|
||||
}
|
||||
} else {
|
||||
// Bei refresh=1: leeren Cache-Eintrag löschen damit neu gesucht wird
|
||||
if (forceRefresh) {
|
||||
db.prepare('DELETE FROM xrel_cache WHERE cache_key=?').run(cacheKey);
|
||||
}
|
||||
|
||||
|
||||
@@ -467,25 +467,23 @@ function MovieModal({ tmdbId, onClose, mobile, onHasXrel }) {
|
||||
api(`/tools/media/movie/${tmdbId}`)
|
||||
.then(d => { setDetail(d); setLoading(false); })
|
||||
.catch(e => { setError(e.message); setLoading(false); });
|
||||
// Cached Releases sofort laden falls vorhanden
|
||||
api(`/tools/media/movie/${tmdbId}/xrel`)
|
||||
.then(d => { if (d.xrel?.length) { setXrel(d.xrel); onHasXrel?.(tmdbId); } })
|
||||
.catch(()=>{});
|
||||
const prev = document.body.style.overflow;
|
||||
document.body.style.overflow = 'hidden';
|
||||
return () => { document.body.style.overflow = prev; };
|
||||
}, [tmdbId]);
|
||||
|
||||
const searchXrel = async (refresh = false) => {
|
||||
const searchXrel = async () => {
|
||||
if (!detail) return;
|
||||
setXrelLoading(true);
|
||||
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({
|
||||
title: detail.title || '',
|
||||
orig: detail.original_title || '',
|
||||
imdb_id: detail.imdb_id || '',
|
||||
refresh: '1',
|
||||
});
|
||||
if (refresh) params.set('refresh', '1');
|
||||
const d = await api(`/tools/media/movie/${tmdbId}/xrel?${params}`);
|
||||
setXrel(d.xrel || []);
|
||||
if (d.has_xrel) onHasXrel?.(tmdbId);
|
||||
@@ -631,7 +629,7 @@ function MovieModal({ tmdbId, onClose, mobile, onHasXrel }) {
|
||||
<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>
|
||||
<button
|
||||
onClick={() => searchXrel(xrel !== null)}
|
||||
onClick={() => searchXrel()}
|
||||
disabled={xrelLoading}
|
||||
style={{
|
||||
fontSize:10, fontFamily:'monospace', cursor: xrelLoading ? 'default' : 'pointer',
|
||||
@@ -640,7 +638,7 @@ function MovieModal({ tmdbId, onClose, mobile, onHasXrel }) {
|
||||
borderRadius:6, padding:'3px 10px', flexShrink:0,
|
||||
}}
|
||||
>
|
||||
{xrelLoading ? '⏳ Suche…' : xrel === null ? '🔍 Suchen' : '🔄 Aktualisieren'}
|
||||
{xrelLoading ? '⏳ Suche…' : xrel === null ? '🔍 Nach Releases suchen' : '🔄 Erneut suchen'}
|
||||
</button>
|
||||
</div>
|
||||
{xrel !== null && xrel.length === 0 && (
|
||||
|
||||
Reference in New Issue
Block a user