feat(up): capture follower snapshots at ingest and backfill history
This commit is contained in:
1 parent
4942d1d161
commit
519fc39fca
8 files changed
+401
-14
No files matched your search
@@ -410,12 +410,14 @@ class Repository:
|
||||
following: int | None = None,
|
||||
now: int | None = None,
|
||||
backfilled: bool = False,
|
||||
live_since: int | None = None,
|
||||
) -> int:
|
||||
"""写入 UP 粉丝快照,并补齐该 UP 尚未记录粉丝数的视频。
|
||||
|
||||
``follower_first`` 只在首次插入时写入;``follower_latest`` 每次刷新都会
|
||||
更新。视频上的 ``up_follower`` 是入库时快照,已有值不会被覆盖。返回本次
|
||||
补齐的视频数。
|
||||
更新。视频上的 ``up_follower`` 是入库时快照,已有值不会被覆盖。传入
|
||||
``live_since`` 时,只有 ``first_seen >= live_since`` 的视频视为实时采集,
|
||||
更早的视频标记为回填。返回本次补齐的视频数。
|
||||
"""
|
||||
now = self._now() if now is None else int(now)
|
||||
mid = int(mid)
|
||||
@@ -436,14 +438,29 @@ class Repository:
|
||||
""",
|
||||
(mid, name, follower, following_value, now, follower, now),
|
||||
)
|
||||
cursor = conn.execute(
|
||||
"""
|
||||
UPDATE video
|
||||
SET up_follower = ?, up_follower_at = ?, up_follower_backfilled = ?
|
||||
WHERE up_mid = ? AND up_follower IS NULL
|
||||
""",
|
||||
(follower, now, backfill_flag, mid),
|
||||
)
|
||||
if live_since is None:
|
||||
cursor = conn.execute(
|
||||
"""
|
||||
UPDATE video
|
||||
SET up_follower = ?, up_follower_at = ?, up_follower_backfilled = ?
|
||||
WHERE up_mid = ? AND up_follower IS NULL
|
||||
AND status IN ('active', 'unfaved')
|
||||
""",
|
||||
(follower, now, backfill_flag, mid),
|
||||
)
|
||||
else:
|
||||
cursor = conn.execute(
|
||||
"""
|
||||
UPDATE video
|
||||
SET up_follower = ?, up_follower_at = ?,
|
||||
up_follower_backfilled = CASE
|
||||
WHEN first_seen >= ? THEN 0 ELSE 1
|
||||
END
|
||||
WHERE up_mid = ? AND up_follower IS NULL
|
||||
AND status IN ('active', 'unfaved')
|
||||
""",
|
||||
(follower, now, int(live_since), mid),
|
||||
)
|
||||
return max(cursor.rowcount, 0)
|
||||
|
||||
return self.db.write(run)
|
||||
|
||||
Reference in new issue
Block a user