fix(search): release covered episodes when remaining missing are all unreleased (#7587)

This commit is contained in:
irab-liu
2026-11-24 22:34:52 +08:00
committed by GitHub
parent 7834a64890
commit 7aba9d8d6d
2 changed files with 41 additions and 4 deletions

View File

@@ -766,6 +766,13 @@ class SearchScan:
self.collection.deepen(ready - settled - cached)
self.checkpoint()
def _covered_targets(self) -> set[str]:
"""
未尝试候选仍覆盖的未提交目标,供第一页先交和站点未收录早停判断使用。
"""
return {target for key in self.candidates if key not in self.attempted
for target in self._coverage(key)}
def _first_pass_targets(self) -> set[str]:
"""
各站第一页到齐后可以先提交的目标,和只搜第一页时一样快;没选中的由 choose 转入深页兜底。
@@ -776,7 +783,7 @@ class SearchScan:
只有整包能先交,全套散集不算,避免深页的整季包失去被选中的机会。
"""
untried = [key for key in self.candidates if key not in self.attempted]
covered = {target for key in untried for target in self._coverage(key)}
covered = self._covered_targets()
remaining = set(self.collection.remaining)
if self.prefer_complete:
# 首次下载优先整包:只有单个资源就覆盖全部缺集才先交,散集凑齐也继续找整包。
@@ -863,9 +870,15 @@ class SearchScan:
continue
advanced = self.step(key) or advanced
ready = self.collection.ready(full=self.full)
if not self.first_pass_done and not self.complete_scan and self.collection.first_pages_ready():
self.first_pass_done = True
ready |= self._first_pass_targets()
if not self.complete_scan and self.collection.first_pages_ready():
if not self.first_pass_done:
self.first_pass_done = True
ready |= self._first_pass_targets()
elif (not self.full and self.collection.pending and self.collection.unreleased()
and self.collection.pending <= self._covered_targets()):
# 已就绪集都有候选、其余缺集均为站点未收录时,提交后即可结束本轮;
# 否则来源无法累积关闭证据,只能翻到页数上限才释放这些集。
ready |= self.collection.pending
if ready:
self.choose(ready, submit)
if self.execution and time.monotonic() - started >= SEARCH_SLICE_SECONDS:

View File

@@ -65,6 +65,14 @@ def torrent(episode, version=1):
enclosure=f"https://site.example/download?id={episode}{version}")
def unknown_torrent(page):
"""
构造标题为空的资源,使识别结果保持未知,阻止来源累积关闭证据。
"""
return TorrentInfo(site=1, description=f"unknown-{page}", title="",
enclosure=f"https://site.example/download?id=unknown-{page}")
def pages(owner, monkeypatch, data):
"""
用内存页面替换站点请求,并返回请求页码记录。
@@ -1199,6 +1207,22 @@ def test_ongoing_series_releases_round_after_available_episodes_are_submitted(ow
assert "还缺 E1006-E1007(站点上还没有,之后的定时检查会继续找)" in scan.progress_text()
def test_resumed_scan_submits_available_episode_instead_of_paging_to_limit(owner, monkeypatch):
"""
已就绪集已有候选、其余缺集均为站点未收录时,恢复的检查点也应提交后结束,
不因来源无法累积关闭证据而翻到页数上限。
"""
calls = pages(owner, monkeypatch, {page: [torrent(16), unknown_torrent(page)] for page in range(20)})
submitted = []
scan = SearchScan(owner=owner, plan=plan(list(range(16, 35))))
scan.first_pass_done = True
scan.run(lambda _items, ready: submitted.append(set(ready)) or ready)
assert calls == [0]
assert submitted == [{"1:16"}]
assert scan.ended
assert scan.collection.remaining == {f"1:{ep}" for ep in range(17, 35)}
def test_only_unreleased_episodes_check_first_page_and_do_not_try_aliases(owner, monkeypatch):
"""
只缺未播出集数时检查首个关键词首页,不继续尝试别名。