fix(offers): background refresh + skip unchanged matching
Two things made Opdater show 'Opdatering fejlede': the refresh ran synchronously (so a slow, rate-limited translate timed out the browser) and a 429 returned 502. Now: - /api/offers/refresh starts the work in a background thread and returns immediately; the button says 'Opdaterer i baggrunden' and reloads a bit later as batches land. A lock prevents overlapping runs. - match_offers_ai skips the Claude call when the offer set is unchanged since the last successful match (hashed), so it runs ~weekly (when the avis turns over), not every daily refresh — fewer calls, less cost, less rate pressure.
This commit is contained in:
@@ -156,14 +156,15 @@ async function refreshOffers() {
|
||||
const btn = document.getElementById('refresh-btn');
|
||||
btn.textContent = '⟳ Henter…'; btn.disabled = true;
|
||||
try {
|
||||
const res = await fetch('/api/offers/refresh', {method: 'POST'});
|
||||
const data = await res.json();
|
||||
if (data.ok) { window.location.reload(); return; }
|
||||
alert('Opdatering fejlede. Prøv igen om lidt.');
|
||||
// The refresh runs in the background (translation can be slow under rate
|
||||
// limits), so we just kick it off and reload a little later to show
|
||||
// progress — the page fills in as batches complete.
|
||||
await fetch('/api/offers/refresh', {method: 'POST'});
|
||||
btn.textContent = '⟳ Opdaterer i baggrunden…';
|
||||
setTimeout(function () { window.location.reload(); }, 12000);
|
||||
} catch (e) {
|
||||
alert('Opdatering fejlede. Prøv igen om lidt.');
|
||||
btn.textContent = '⟳ Opdater'; btn.disabled = false;
|
||||
}
|
||||
btn.textContent = '⟳ Opdater'; btn.disabled = false;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user