fix(monitor): 卡死的一轮不再堵住调度循环;矩阵补总获赞和首条视频日期
Deploy VitePress site to Pages / build (push) Canceled after 0s
Deploy VitePress site to Pages / Deploy (push) Canceled after 0s

「抓不到最新的」有两个叠加的原因:

1. 采集卡死时 `_run_due_task` 是内联 await,execute_task 里的 wait_for 又在等
   一个不响应取消的协程 —— 整个调度循环(连同自动追加、每日推送、其他任务)
   一起停 65 分钟。现在采集丢到后台任务里跑,循环照常 tick,reap_stale_runs
   也能按时回收。实测任务 25 最近 8 次运行有 4 次这样。
2. 超级编导自动追加在 10-25 因密码错误被停到 11-24(防锁号),新作品进不来。
   已把 25 号的调度钟拨回现在,补进了 10-31 那条。

标签矩阵:博主名字左边在粉丝数之后加「主页总获赞」和「第一条视频发布日期」
(查全库最早的作品时间,不受 7/14/30 天窗口限制)。
This commit is contained in:
2026-11-02 10:24:36 +08:00
parent cd2a276630
commit c06848ae98
5 changed files with 215 additions and 17 deletions
+32 -1
View File
@@ -1578,7 +1578,9 @@ async def daily_tag_matrix(
返回**长表结构**,转置由前端做:
{"dates": ["2026-10-21", ...], # 新到旧
"creators": [{"hash": ..., "name": ...}], # 按昵称排序
"creators": [{"hash": ..., "name": ..., "fans": 1200,
"total_favorited": 83000,
"first_published_at": 1780000000000}], # 按昵称排序
"cells": {"2026-10-21": {"<hash>": {
"count": 2, "tags": ["大字报", "养号"],
"likes": 120, "comments": 8, "collected": 30, "shares": 4,
@@ -1701,6 +1703,7 @@ async def daily_tag_matrix(
MonitorCreatorStat.nickname,
MonitorCreatorStat.captured_at,
MonitorCreatorStat.fans,
MonitorCreatorStat.total_favorited,
).where(
MonitorCreatorStat.task_id.in_(task_ids),
MonitorCreatorStat.creator_hash != "",
@@ -1711,11 +1714,20 @@ async def daily_tag_matrix(
# 粉丝数是给博主列显示用的「最近一次已知值」。某一轮没解析出来(None)不让它把
# 之前的好数字盖掉 —— 一个号有几千粉丝,不会因为这一轮没读到就变成不知道。
latest_fans: Dict[str, tuple] = {}
# 主页上的「获赞总数」,和粉丝数一样取最近一次读到的值。
latest_likes: Dict[str, tuple] = {}
for stat in stat_rows:
if stat.fans is not None:
current_fans = latest_fans.get(stat.creator_hash)
if current_fans is None or stat.captured_at > current_fans[1]:
latest_fans[stat.creator_hash] = (stat.fans, stat.captured_at)
if stat.total_favorited is not None:
current_likes = latest_likes.get(stat.creator_hash)
if current_likes is None or stat.captured_at > current_likes[1]:
latest_likes[stat.creator_hash] = (
stat.total_favorited,
stat.captured_at,
)
# **空昵称不算名字。** 资料接口偶尔会回一个空对象(昵称、sec_uid、粉丝、
# 作品数全空),如果把这一轮当最新快照,就会用一个空字符串把之前的好名字
# 盖掉,界面上变成「未知(hash)」。实测线上有两个号就是这么丢的名字。
@@ -1802,6 +1814,23 @@ async def daily_tag_matrix(
# 作品是按发布时间倒序取回来的,明细按时间正序更好读(1、2、3…)。
bucket["details"].reverse()
# 博主的**第一条视频**发布时间。查全库,不受上面 days 窗口的限制 —— 一个号最早的
# 作品很可能在窗口之外,而「这个号做了多久」看的就是它。
first_rows = (
await session.execute(
select(MonitorNote.creator_hash, func.min(MonitorNote.published_at))
.where(
MonitorNote.task_id.in_(task_ids),
MonitorNote.published_at.is_not(None),
MonitorNote.creator_hash != "",
)
.group_by(MonitorNote.creator_hash)
)
).all()
first_published: Dict[str, int] = {
creator_hash: first_at for creator_hash, first_at in first_rows if first_at
}
creators = [
{
"hash": hash_,
@@ -1809,6 +1838,8 @@ async def daily_tag_matrix(
# 没有账号快照的博主(作品模式刚导入、还没跑过一轮)就是 None,
# 前端据此不画那个数字,而不是显示 0。
"fans": latest_fans.get(hash_, (None, 0))[0],
"total_favorited": latest_likes.get(hash_, (None, 0))[0],
"first_published_at": first_published.get(hash_),
}
for hash_, name in known.items()
]