Spaces:
Paused
Paused
feat: 보관함 NEW 자동 검사 — 15분 주기 폴링 + 탭 복귀 트리거
Browse files기존엔 페이지 새로고침/카드 클릭 때만 검사 → 사이트 열어두면 새 회차
감지 불가. 서버는 24/7 돌지만 클라이언트 트리거 없으면 무의미.
- setInterval 15분: visible 상태일 때만 refreshLatestLabels (hidden 탭 절약)
- visibilitychange visible: 마지막 호출 후 5분 이상 경과시 즉시 검사
(탭 전환 폭주 방지 디바운스)
- _lastLatestLabelsAt 타임스탬프로 호출 간격 관리
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- index.html +19 -1
index.html
CHANGED
|
@@ -2369,9 +2369,12 @@ async function refreshAll() {
|
|
| 2369 |
}
|
| 2370 |
}
|
| 2371 |
}
|
| 2372 |
-
// 보관함 NEW 자동 감지 — 부팅
|
| 2373 |
// /api/latest-labels는 캐시된 episodes에서 최신 라벨만 뽑아 즉시 반환.
|
| 2374 |
// 캐시 miss인 항목은 서버가 백그라운드로 fetchEpisodes 트리거 → 다음 호출 때 hit.
|
|
|
|
|
|
|
|
|
|
| 2375 |
async function refreshLatestLabels() {
|
| 2376 |
if (!favs.length) return;
|
| 2377 |
const ids = favs.map(f => f.id).join(',');
|
|
@@ -2393,6 +2396,7 @@ async function refreshLatestLabels() {
|
|
| 2393 |
}
|
| 2394 |
}
|
| 2395 |
if (changed) { saveFavs(); renderFavs(); }
|
|
|
|
| 2396 |
// pending이 있으면 서버가 백그라운드 갱신 중 — 잠시 후 한 번 더 호출해서 새 결과 받기
|
| 2397 |
if (r.pending && r.pending.length) {
|
| 2398 |
setTimeout(() => refreshLatestLabels().catch(() => {}), 20000);
|
|
@@ -2402,6 +2406,20 @@ async function refreshLatestLabels() {
|
|
| 2402 |
}
|
| 2403 |
}
|
| 2404 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2405 |
// E-4: ↻ 클릭 — 알림 점이 있으면 첫 NEW 카드로 스크롤. 없으면 새 회차 확인.
|
| 2406 |
async function refreshOrScroll() {
|
| 2407 |
const hasNew = favs.some(f => f.latestLabel && f.lastFinishedLabel && f.latestLabel !== f.lastFinishedLabel && f.lastSeenLabel !== f.latestLabel);
|
|
|
|
| 2369 |
}
|
| 2370 |
}
|
| 2371 |
}
|
| 2372 |
+
// 보관함 NEW 자동 감지 — 부팅 + 주기 폴링 + 탭 visibility 복귀 시 호출.
|
| 2373 |
// /api/latest-labels는 캐시된 episodes에서 최신 라벨만 뽑아 즉시 반환.
|
| 2374 |
// 캐시 miss인 항목은 서버가 백그라운드로 fetchEpisodes 트리거 → 다음 호출 때 hit.
|
| 2375 |
+
let _lastLatestLabelsAt = 0;
|
| 2376 |
+
const LATEST_LABELS_MIN_INTERVAL = 5 * 60 * 1000; // visibility 트리거 최소 5분 간격 (탭 전환 폭주 방지)
|
| 2377 |
+
const LATEST_LABELS_POLL_INTERVAL = 15 * 60 * 1000; // 주기 폴링 15분
|
| 2378 |
async function refreshLatestLabels() {
|
| 2379 |
if (!favs.length) return;
|
| 2380 |
const ids = favs.map(f => f.id).join(',');
|
|
|
|
| 2396 |
}
|
| 2397 |
}
|
| 2398 |
if (changed) { saveFavs(); renderFavs(); }
|
| 2399 |
+
_lastLatestLabelsAt = Date.now();
|
| 2400 |
// pending이 있으면 서버가 백그라운드 갱신 중 — 잠시 후 한 번 더 호출해서 새 결과 받기
|
| 2401 |
if (r.pending && r.pending.length) {
|
| 2402 |
setTimeout(() => refreshLatestLabels().catch(() => {}), 20000);
|
|
|
|
| 2406 |
}
|
| 2407 |
}
|
| 2408 |
|
| 2409 |
+
// 15분마다 주기 폴링 — 페이지가 visible일 때만 (hidden 탭에선 불필요한 호출 절약)
|
| 2410 |
+
setInterval(() => {
|
| 2411 |
+
if (document.visibilityState === 'visible') {
|
| 2412 |
+
refreshLatestLabels().catch(() => {});
|
| 2413 |
+
}
|
| 2414 |
+
}, LATEST_LABELS_POLL_INTERVAL);
|
| 2415 |
+
|
| 2416 |
+
// 탭 전환·앱 백그라운드 복귀 시 즉시 검사 (단 마지막 호출 후 5분 이상 지났을 때만)
|
| 2417 |
+
document.addEventListener('visibilitychange', () => {
|
| 2418 |
+
if (document.visibilityState !== 'visible') return;
|
| 2419 |
+
if (Date.now() - _lastLatestLabelsAt < LATEST_LABELS_MIN_INTERVAL) return;
|
| 2420 |
+
refreshLatestLabels().catch(() => {});
|
| 2421 |
+
});
|
| 2422 |
+
|
| 2423 |
// E-4: ↻ 클릭 — 알림 점이 있으면 첫 NEW 카드로 스크롤. 없으면 새 회차 확인.
|
| 2424 |
async function refreshOrScroll() {
|
| 2425 |
const hasNew = favs.some(f => f.latestLabel && f.lastFinishedLabel && f.latestLabel !== f.lastFinishedLabel && f.lastSeenLabel !== f.latestLabel);
|