feat(stats): add migration v7 visit table and client-ip helpers
This commit is contained in:
1 parent
b0c53e8a2f
commit
cdd11823b9
8 files changed
+531
-15
No files matched your search
@@ -224,6 +224,26 @@ MIGRATIONS: tuple[Migration, ...] = (
|
||||
"ALTER TABLE video ADD COLUMN up_face TEXT",
|
||||
),
|
||||
),
|
||||
Migration(
|
||||
version=7,
|
||||
name="visit access statistics",
|
||||
statements=(
|
||||
# 访问统计按 (日期, IP, 路由) 聚合:PV = SUM(hits),UV = COUNT(DISTINCT ip)。
|
||||
# 数据先落内存缓冲、批量 upsert,因此 hits 累加而非逐条插入。
|
||||
"""
|
||||
CREATE TABLE visit (
|
||||
stat_date TEXT NOT NULL,
|
||||
ip TEXT NOT NULL,
|
||||
path TEXT NOT NULL,
|
||||
hits INTEGER NOT NULL DEFAULT 0,
|
||||
first_at INTEGER NOT NULL,
|
||||
last_at INTEGER NOT NULL,
|
||||
PRIMARY KEY (stat_date, ip, path)
|
||||
)
|
||||
""",
|
||||
"CREATE INDEX idx_visit_date ON visit(stat_date)",
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user