Skip to content

feat(subscribe): 新增订阅总集数刷新与完成检查链式事件#5860

Merged
jxxghp merged 2 commits into
jxxghp:v2from
InfinityPacer:claude/feat/subscribe-lifecycle-events
May 30, 2026
Merged

feat(subscribe): 新增订阅总集数刷新与完成检查链式事件#5860
jxxghp merged 2 commits into
jxxghp:v2from
InfinityPacer:claude/feat/subscribe-lifecycle-events

Conversation

@InfinityPacer

Copy link
Copy Markdown
Contributor

背景

订阅的「总集数推算」与「完成判定」目前在主程序内硬编码:总集数恒取 TMDB 季集数 len(seasons[season]),完成判定恒以 lack=0 收口。缺少像 Resource*/Transfer* 那样的链式扩展点,外部无法按自身策略修正集数口径或否决一次自动完成。

改动

对标既有链式事件体系,新增两个订阅域链式事件(ChainEventData 派生,输入/输出分区,统一 cancel/updated/source/reason):

SubscribeEpisodesRefresh(subscribe.episodes.refresh)
推算某季总集数时发出,外部可覆盖 total_episode。统一覆盖全部 4 个推算点:创建订阅(同步/异步)、元数据刷新 check()、完成前兜底 __refresh_total_episode_before_completion;为此抽出公共方法 __apply_episodes_refresh(含异步版),并将兜底方法改为实例方法。覆盖值仍受各调用点既有校验(如「只增不减」)约束。

SubscribeCompletionCheck(subscribe.completion.check)
__finish_subscribe 写历史并删除之前发出,外部可否决本次自动完成;被否决时仅跳过收口、不写订阅状态。挂载于唯一收口执行点,覆盖普通订阅与洗版的全部完成路径;命令式手动删除不受影响。

兼容性

无监听者或外部未覆盖/未否决时,输出默认值(updated=False / cancel=False)使主程序行为与改动前等价,属纯增量扩展点。

验证

  • python -m py_compile 三处改动文件通过;
  • 两个事件数据类可经 app.schemas 导入,默认 cancel / updated 均为 False;
  • pylint -E 对改动文件零 error。

本 PR 为 Claude Code 协作提交。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces two new event types, SubscribeEpisodesRefresh and SubscribeCompletionCheck, along with their corresponding event data schemas. These events allow external plugins to override the default total episode count (calculated via TMDB) and to veto or cancel the automatic completion of a subscription. In app/chain/subscribe.py, these events are integrated into the subscription creation, refresh, precheck, and completion flows. The review feedback points out a potential issue where overriding the total episode count to a smaller value could result in a negative lack_episode count, and suggests using max(..., 0) to prevent this.

Comment thread app/chain/subscribe.py Outdated
tmdbid=subscribe.tmdbid, doubanid=subscribe.doubanid,
subscribe_id=subscribe.id, scene="refresh")
# 总集数增长按 delta 同步抬升 lack
lack_episode = (subscribe.lack_episode or 0) + (total_episode - (subscribe.total_episode or 0))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

当外部插件或事件将 total_episode 覆盖为比当前值更小的值时(例如,修正集数口径),计算得到的 lack_episode 可能会变成负数。建议使用 max(..., 0) 进行保护,以防止 lack_episode 出现负值,确保数据一致性。

Suggested change
lack_episode = (subscribe.lack_episode or 0) + (total_episode - (subscribe.total_episode or 0))
lack_episode = max((subscribe.lack_episode or 0) + (total_episode - (subscribe.total_episode or 0)), 0)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@InfinityPacer InfinityPacer force-pushed the claude/feat/subscribe-lifecycle-events branch from 014d62e to a2171f4 Compare May 29, 2026 17:45
@jxxghp jxxghp merged commit 69a064e into jxxghp:v2 May 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants