feat(matrix): 「第一条视频」改成主页最早一条,后台翻页扫描 + 缓存
要的是这个博主**最早发的**那条(可能根本不在监控目标里),不是主页第一屏。 按游标翻到底才知道,所以: - 新增 monitor_creator_first_video 缓存表,按 sec_uid 存最早发布时间, 30 天内不再扫; - 调度器后台任务慢慢扫(每页 20 条、页间 0.5 秒、单次最多 50 页 / 3 分钟), 不占调度循环; - 矩阵只读缓存,读不到退回库里最早的一条作品; - 失败只锁 6 小时再试,不会把没扫到的号锁 30 天。 同时撤掉上一版「每轮采集多问一次主页最新视频」的实现(方向反了)。
This commit is contained in:
+29
-4
@@ -411,14 +411,39 @@ class MonitorCreatorStat(MonitorBase):
|
||||
total_favorited: Mapped[Optional[int]] = mapped_column(BigInteger)
|
||||
works_count: Mapped[Optional[int]] = mapped_column(BigInteger)
|
||||
following: Mapped[Optional[int]] = mapped_column(BigInteger)
|
||||
# 这个博主**主页上最新一条视频**的发布时间(毫秒)。作品列表是按时间倒序的,
|
||||
# 「第一条」就是最新那条 —— 它可能根本不在监控的目标里(自然发的、别的活动发的),
|
||||
# 但能回答「他最近还发不发」。拿不到(接口挡了/超时)就留 None。
|
||||
latest_published_at: Mapped[Optional[int]] = mapped_column(BigInteger)
|
||||
|
||||
captured_at: Mapped[int] = mapped_column(BigInteger, nullable=False, index=True)
|
||||
|
||||
|
||||
class MonitorCreatorFirstVideo(MonitorBase):
|
||||
"""博主主页**最早一条视频**的发布时间缓存。
|
||||
|
||||
抖音的作品列表是按时间倒序、按游标翻页的 —— 想知道「这个号第一条视频是什么时候
|
||||
发的」,只能一页页翻到最后一页(几十上百条作品 = 十几次请求),而且接口时不时超时。
|
||||
所以扫一次、存下来,30 天内不再扫:老作品不会变,这个值几乎是个常量。
|
||||
|
||||
矩阵页只读这张表,不在这里发任何请求。
|
||||
"""
|
||||
|
||||
__tablename__ = "monitor_creator_first_video"
|
||||
__table_args__ = (
|
||||
UniqueConstraint("platform", "creator_id", name="uq_creator_first_video"),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
platform: Mapped[str] = mapped_column(String(16), nullable=False, index=True)
|
||||
# 主页 id(抖音是 sec_uid)。哈希是单向的,查不了主页。
|
||||
creator_id: Mapped[str] = mapped_column(String(128), nullable=False, index=True)
|
||||
creator_hash: Mapped[str] = mapped_column(String(64), nullable=False, default="")
|
||||
# 毫秒。**没扫到时留 NULL**,界面上退回「库里最早的一条作品」。
|
||||
first_published_at: Mapped[Optional[int]] = mapped_column(BigInteger)
|
||||
scanned_pages: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
||||
# 是否翻到了最后一页。到了上限(作品特别多)时为 False,值只是「翻到的部分里最早的」。
|
||||
complete: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
|
||||
checked_at: Mapped[int] = mapped_column(BigInteger, nullable=False, default=0, index=True)
|
||||
error: Mapped[str] = mapped_column(String(500), nullable=False, default="")
|
||||
|
||||
|
||||
class MonitorNoteAlias(MonitorBase):
|
||||
"""给**作品**起的备注。
|
||||
|
||||
|
||||
Reference in New Issue
Block a user