feat(stats): 일별 방문자 집계 추가
page_visits 테이블((visit_date, device_id) 유니크) — 하루 1기기 1회 집계. POST /api/visit(접속 기록), GET /api/admin/visits(일별 순수 방문자, Bearer). 프론트는 App 마운트 시 1회 recordVisit() 호출. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
51352c7c5c
commit
140e15fb9f
7 files changed
+97
-5
No files matched your search
+21
-1
@@ -9,10 +9,11 @@
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import date, datetime
|
||||
|
||||
from sqlalchemy import (
|
||||
Boolean,
|
||||
Date,
|
||||
DateTime,
|
||||
ForeignKey,
|
||||
Integer,
|
||||
@@ -178,3 +179,22 @@ class UserPoints(Base):
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now(), onupdate=func.now()
|
||||
)
|
||||
|
||||
|
||||
class PageVisit(Base):
|
||||
"""페이지 방문 — 하루(KST)에 같은 기기(device_id)는 1회만 기록(순수 방문자 수).
|
||||
|
||||
일별 집계 = visit_date 로 GROUP BY COUNT. 같은 날 재방문은 유니크 제약으로 무시.
|
||||
"""
|
||||
|
||||
__tablename__ = "page_visits"
|
||||
__table_args__ = (
|
||||
UniqueConstraint("visit_date", "device_id", name="uq_visit_date_device"),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
visit_date: Mapped[date] = mapped_column(Date, index=True) # KST 기준 날짜
|
||||
device_id: Mapped[str] = mapped_column(String) # 비로그인 식별 (localStorage uuid)
|
||||
created_at: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True), server_default=func.now()
|
||||
)
|
||||
Reference in new issue
Block a user