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
+25
View File
@@ -146,6 +146,7 @@ def dashboard_page(
)
ctx["metric"] = metric if metric in ("gross", "commission", "net") else "net"
ctx["auto_sync"] = _auto_sync_ctx(store, "sales")
ctx["update_watch"] = _update_watch("sales", user)
_unit_ctx(request, ctx)
return render_template(request, "performance/index.html", {**common.base_ctx(user, active_tab="dashboard"), **ctx})
@@ -173,6 +174,29 @@ def _auto_sync_ctx(store: Any, kind: str) -> dict[str, Any] | None:
"label": auto_sync.describe(sched)}
def _update_watch(kind: str, user: dict[str, Any]) -> dict[str, str]:
"""화면 자동 새로 그리기(2026-10-26) — 그린 시점에 마지막으로 끝난 업데이트(보는 사람 것 제외). 화면이
GET /api/update-status 로 이 값이 바뀌면(자동 업데이트 등이 끝나면) 새로 고친다."""
from . import jobs # noqa: WPS433
job = jobs.last_finished(kind, exclude_user=user.get("email", ""))
return {"kind": kind, "seen": job.id if job else ""}
@router.get("/api/update-status")
def api_update_status(request: Request, kind: str = "sales") -> JSONResponse:
"""지금 그 종류 업데이트가 도는지 · 마지막으로 끝난 업데이트(보는 사람이 시작한 것 제외) — 화면이 20초마다 본다.
메모리의 진행 작업만 보고 DB 는 안 읽는다."""
from . import jobs # noqa: WPS433
_, user = common.require_store(request)
if kind not in jobs.KINDS:
raise HTTPException(status_code=404, detail="알 수 없는 업데이트 종류입니다.")
job = jobs.last_finished(kind, exclude_user=user.get("email", ""))
return JSONResponse({"kind": kind, "running": jobs.running_job(kind) is not None, "done": job.id if job else "",
"user": job.user if job else ""})
def _unit_ctx(request: Request, ctx: dict[str, Any]) -> None:
"""매출 단위(원·천원·백만원) — 실적 설정 "보기 설정"이 이 브라우저 쿠키(perf_unit)에 둔다. 템플릿은 amt(v) 로 그린다."""
from .dashboard import UNIT_COOKIE, UNITS, amount_text, normalize_unit # noqa: WPS433
@@ -221,6 +245,7 @@ def ads_page(
ctx["ad_last_update_at"] = last_ad_update_at(store)
ctx["ad_running"] = jobs.running_job("ads") is not None
ctx["auto_sync"] = _auto_sync_ctx(store, "ads")
ctx["update_watch"] = _update_watch("ads", user)
return render_template(request, "performance/ads.html",
{**common.base_ctx(user, active_tab="ads", page_title="광고비"), **ctx})