feat: EOD 23:15 seal + midnight seed shell for video/fans
Move daily snapshot/fans to 23:15 and add 00:01 seed that clones last_completed ok=1 rows into today without advancing completed. Evening runs force through seed markers; growth previous is per-aid adjacent. Home shows short-update clock + 全站数据 date, and 收录视频 counts.
This commit is contained in:
1 parent
374b138041
commit
8a9cb21408
17 files changed
+520
-39
No files matched your search
@@ -10,7 +10,7 @@ from __future__ import annotations
|
||||
import sqlite3
|
||||
import time
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, Iterable, Mapping
|
||||
from typing import Any, Iterable, Mapping, Sequence
|
||||
|
||||
from .config import FolderConfig
|
||||
from .database import Database
|
||||
@@ -727,6 +727,83 @@ class Repository:
|
||||
)
|
||||
self.db.write(run)
|
||||
|
||||
def copy_ok_snapshots(
|
||||
self,
|
||||
source_date: str,
|
||||
target_date: str,
|
||||
*,
|
||||
captured_at: int,
|
||||
src: str = "seed",
|
||||
) -> int:
|
||||
"""将 source_date 的 ok=1 行复制到 target_date;已有 target 行则跳过。"""
|
||||
def run(conn: sqlite3.Connection) -> int:
|
||||
cur = conn.execute(
|
||||
"""
|
||||
INSERT INTO snapshot(
|
||||
stat_date, aid, "view", "like", favorite, coin,
|
||||
share, reply, danmaku, captured_at, ok, err, src
|
||||
)
|
||||
SELECT
|
||||
?, aid, "view", "like", favorite, coin,
|
||||
share, reply, danmaku, ?, 1, NULL, ?
|
||||
FROM snapshot
|
||||
WHERE stat_date = ? AND ok = 1
|
||||
AND aid NOT IN (
|
||||
SELECT aid FROM snapshot WHERE stat_date = ?
|
||||
)
|
||||
""",
|
||||
(target_date, int(captured_at), src, source_date, target_date),
|
||||
)
|
||||
return int(cur.rowcount or 0)
|
||||
return self.db.write(run)
|
||||
|
||||
def copy_ok_up_stats(
|
||||
self,
|
||||
source_date: str,
|
||||
target_date: str,
|
||||
*,
|
||||
captured_at: int,
|
||||
mids: Sequence[int] | None = None,
|
||||
) -> int:
|
||||
"""将 source_date 的 ok=1 粉丝行复制到 target_date;已有 target 行则跳过。"""
|
||||
def run(conn: sqlite3.Connection) -> int:
|
||||
if mids is not None:
|
||||
mid_list = [int(m) for m in mids]
|
||||
if not mid_list:
|
||||
return 0
|
||||
placeholders = ",".join("?" for _ in mid_list)
|
||||
cur = conn.execute(
|
||||
f"""
|
||||
INSERT INTO up_stat(
|
||||
stat_date, mid, follower, following, captured_at, ok
|
||||
)
|
||||
SELECT ?, mid, follower, following, ?, 1
|
||||
FROM up_stat
|
||||
WHERE stat_date = ? AND ok = 1 AND mid IN ({placeholders})
|
||||
AND mid NOT IN (
|
||||
SELECT mid FROM up_stat WHERE stat_date = ?
|
||||
)
|
||||
""",
|
||||
(target_date, int(captured_at), source_date, *mid_list, target_date),
|
||||
)
|
||||
else:
|
||||
cur = conn.execute(
|
||||
"""
|
||||
INSERT INTO up_stat(
|
||||
stat_date, mid, follower, following, captured_at, ok
|
||||
)
|
||||
SELECT ?, mid, follower, following, ?, 1
|
||||
FROM up_stat
|
||||
WHERE stat_date = ? AND ok = 1
|
||||
AND mid NOT IN (
|
||||
SELECT mid FROM up_stat WHERE stat_date = ?
|
||||
)
|
||||
""",
|
||||
(target_date, int(captured_at), source_date, target_date),
|
||||
)
|
||||
return int(cur.rowcount or 0)
|
||||
return self.db.write(run)
|
||||
|
||||
def snapshot_counts(self, stat_date: str) -> dict[str, int]:
|
||||
def run(conn: sqlite3.Connection) -> dict[str, int]:
|
||||
rows = conn.execute(
|
||||
|
||||
Reference in new issue
Block a user