feat(performance): 자동 업데이트가 끝나면 매출 실적·광고비 화면 새로 고침

- 화면이 20초마다 GET /api/update-status?kind=sales|ads 로 마지막으로 끝난 업데이트를 보고,
  그린 때(update_watch.seen)와 다르고 도는 중이 아니면 reload (jobs.last_finished — 메모리만, DB 안 읽음)
- 보는 사람이 직접 누른 업데이트는 제외(진행 창이 새로 그림), 매출·광고비 따로
- 칸 입력·창·메뉴·확인 창이 열려 있으면 닫힐 때까지 기다리고 "새 데이터 있음" 안내, 탭이 안 보이면 안 물음
- 테스트: last_finished·update-status API, 브라우저(새로 고침·기다림·종류별)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-26 18:37:39 +09:00
parent fba27772a4
commit 18d2835304
12 changed files with 272 additions and 8 deletions
+1
View File
@@ -146,6 +146,7 @@ a.perf-seg.is-active, a.perf-seg.is-active:link, a.perf-seg.is-active:visited {
.perf-kpi-line-value { font-size: 22px; font-weight: 700; letter-spacing: -.5px; color: var(--color-rich-black); white-space: nowrap; }
/* 다음 자동 업데이트까지 남은 시간(초 단위) — 숫자 폭이 바뀌어도 흔들리지 않게 */
.perf-next-update b { font-variant-numeric: tabular-nums; }
.perf-refresh-note { color: var(--perf-up); font-weight: 600; } /* 자동 업데이트 끝 → 새로 고침 안내 */
.perf-delta { font-weight: 600; }
.perf-delta.is-up { color: var(--perf-good); } /* is-up = 좋음(수수료는 줄어야 좋음, invert) */
.perf-delta.is-down { color: var(--perf-down); }
+43
View File
@@ -993,6 +993,49 @@
// 매출 실적 화면은 늘 수수료 차감 매출로 연다(2026-10-19) — 서버 기본 data-metric="net", 예전에 고른 보기(localStorage)는 쓰지 않음
setMetric(root.dataset.metric || "net");
initNextUpdate(data.auto_sync);
initUpdateWatch(data.update_watch);
}
// 자동 업데이트(다른 사람이 누른 업데이트 포함)가 끝나면 화면 새로 고침(2026-10-26) — 20초마다 GET /api/update-status 로
// 마지막으로 끝난 업데이트를 보고, 화면을 그린 때(update_watch.seen)와 다르고 지금 도는 업데이트가 없으면 reload.
// 칸 입력 중·창(메모·진행 창 등)·확인 창·메뉴가 열려 있으면 닫힐 때까지 기다린다. 탭이 안 보이면 묻지 않고, 다시 보이면 바로 본다.
// 보는 사람이 직접 누른 업데이트는 서버가 빼고 준다(진행 창이 알아서 새로 그림).
const WATCH_MS = 20000;
function initUpdateWatch(w) {
if (!w || !w.kind) return;
const seen = w.seen || "";
let pending = false, asking = false;
function busyUi() {
const a = document.activeElement;
if (a && a !== document.body && (/^(INPUT|TEXTAREA|SELECT)$/.test(a.tagName) || a.isContentEditable)) return true;
return !!document.querySelector(".perf-modal, .perf-ctx, .erp-dialog-backdrop");
}
function note(text) {
const lu = document.getElementById("perf-last-update");
if (!lu) return;
let n = lu.querySelector(".perf-refresh-note");
if (!n) { n = el("span", { class: "perf-refresh-note" }); lu.appendChild(n); }
n.textContent = text;
}
function reloadWhenFree() {
if (busyUi()) {
note(" · 새 데이터 있음 — 입력·창을 닫으면 새로 고칩니다");
setTimeout(reloadWhenFree, 1500);
return;
}
note(" · 새 데이터로 고치는 중…");
location.reload();
}
async function check() {
if (pending || asking || document.hidden) return;
asking = true;
try {
const st = await api("GET", "/performance/api/update-status?kind=" + encodeURIComponent(w.kind));
if (st.done && st.done !== seen && !st.running) { pending = true; reloadWhenFree(); }
} catch (_) { /* 잠깐 끊김·로그아웃 — 다음 차례에 */ } finally { asking = false; }
}
setInterval(check, WATCH_MS);
document.addEventListener("visibilitychange", function () { if (!document.hidden) check(); });
}
// 다음 자동 업데이트까지 남은 시간 — 초 단위 실시간(2026-10-19). 서버가 준 다음 회차·지금 시각(PC 시계 차이 보정)으로 세고,