Skip to content

armgit / peach

Public Imported from GitHub
0

Peach: Local-first video metadata scraper and media manager.

fix(followups): 定时拉取订阅每一轮顺带派补头像存量

longmeidao63fd1689307c
diff --git a/docs/adr/0097-feed-check-dispatches-avatar-stock.md b/docs/adr/0097-feed-check-dispatches-avatar-stock.md
new file mode 100644
index 000000000..63d0b83c8
--- /dev/null
+++ b/docs/adr/0097-feed-check-dispatches-avatar-stock.md
@@ -0,0 +1,31 @@
+# ADR-0097:定时拉取订阅每一轮都派补头像存量
+
+- 状态:Accepted
+- 日期:2026-10-09
+- 修订:ADR-0053 第二条(存量补派的入口)
+
+## 背景
+
+`二の宮すずか` 09-22 建档,馆里只有一部合演 NHDTB-557。gfriends 图库里她名下有六张,来自六个目录;
+不带参照跑一次 `match_gallery`,六张互相认得(ADR-0062),会装上 Moodyz 那张 600×783。
+可她到现在都没有头像,`task_run` 里也没有她的 `entity-avatar` 一行。
+
+补头像后继上线(09-24)时她已经建档,不算新实体,只能等存量补派。存量补派只在资料处理收尾时进行
+(ADR-0053 第二条),而 09-30 之后一轮资料处理都没跑过:没有新片入库,就不会启动资料处理。
+库里 146 位缺头像的女优一条都没派出去,她只有一部作品,排第 96 位。
+
+## 决策
+
+**`feed-check` 结算时也派补头像存量。** 订阅自己的后继排在前面,`MAX_FOLLOWUPS` 剩下的名额全给
+`avatar_followup.stock`。排序和「试过又没变的不再派」(ADR-0053 第三条)都和资料处理收尾那一份
+一样,两处派的是同一份存量,指纹记号也是同一份,同一个实体不会因为有两个入口就被试两次。
+
+补头像不写账本,走自己的通道,和取资料、补别名那条写账本的通道不抢。补别名、补女优资料、
+补厂牌这三份存量仍然只在资料处理收尾时派:它们要写账本,每条要问两三个站,配额由 ADR-0053 定。
+
+## 后果
+
+- 没有资料处理的日子,补头像存量也在推进。一轮大约 60 条,定时拉取一天两三轮,
+ 现有一百多位缺头像的女优几天内都能派完。
+- 判据一个字没变:图库唯一命中、按脸比对、图库互证、封面截脸、馆外封面、小图兜底,各档照旧。
+ 试过却没装上的那些,指纹不变就不会被再派。
diff --git a/src/peach/web_feeds.py b/src/peach/web_feeds.py
index 51e83b6a3..9c9439e23 100644
--- a/src/peach/web_feeds.py
+++ b/src/peach/web_feeds.py
@@ -15,12 +15,15 @@ from datetime import timedelta
from urllib.parse import quote
from . import (
- entities, entry_links, feed_followup, feeds, javdb, performer_alias_followup as alias,
- performer_profile_followup, wants, web_catalog, web_settings, web_wants,
+ avatar_followup, entities, entry_links, feed_followup, feeds, javdb,
+ performer_alias_followup as alias, performer_profile_followup, wants, web_catalog,
+ web_settings, web_wants,
)
from .catalog_rules import normalise_code_key
+from .followups import Attempts, attempts_root
from .jobs import TaskRunConflict
from .http import HttpRequest, public_https_url
+from .task_runs import MAX_FOLLOWUPS
#: 一次拉取的超时与体积上限。JavDB 演员页 78 KB;2 MiB 之外的东西不是演员页,
#: 是被替换成了别的页面。
@@ -189,11 +192,17 @@ def _execute_check(contract, body, job_id: str) -> dict:
batch = codes + feed_followup.backlog(
connection, contract.cover_root, exclude=codes, retry_after=retry_after,
limit=max(0, feed_followup.MAX_BATCH - len(codes)), hidden=hidden)
+ planned = feed_followup.plan(batch)
+ # 余下的名额给缺头像的存量女优(ADR-0097)。资料处理收尾也派这一份,但没有新片
+ # 入库的日子它一轮都不跑,存量就一直停在原地;定时拉取每天都跑。
+ planned += avatar_followup.stock(
+ connection, contract.avatar_root, Attempts(attempts_root(contract.candidate_root)),
+ limit=MAX_FOLLOWUPS - len(planned))
return {"ok": True, "checked": len(rows), "total": len(rows), "results": results,
"added": len(codes),
# 后继由结果声明,调度端统一派(ADR-0040):这里只把清单交出去。
"followups": [dict(key=item.key, task_key=item.task_key, label=item.label)
- for item in feed_followup.plan(batch)]}
+ for item in planned]}
def w_feed_check(contract, body) -> dict:
diff --git a/tests/test_feeds_web.py b/tests/test_feeds_web.py
index c0411c817..cc3f54922 100644
--- a/tests/test_feeds_web.py
+++ b/tests/test_feeds_web.py
@@ -79,6 +79,9 @@ class FeedWebFixture(unittest.TestCase):
self.addCleanup(lambda: setattr(feed_followup, "collect", self._collect))
# 封面装进临时封面目录;取图那一步同样替掉,换成一张现画的横版封套。
self.contract.cover_root = Path(self.temporary.name) / "covers"
+ # 每一轮拉取还会给缺头像的存量女优派补头像,判缺不缺、试没试过都读这两处。
+ self.contract.candidate_root = Path(self.temporary.name) / "generated"
+ self.contract.avatar_root = self.contract.candidate_root / "avatars"
self.cover_misses: set[str] = set()
self.cover_unreachable: set[str] = set()
self.cover_urls: dict[str, str | None] = {}
@@ -500,6 +503,29 @@ class FeedWebTest(FeedWebFixture):
self.assertEqual([item["key"] for item in self._check()["followups"]],
["feed-scrape:HMN-071"])
+ def test_every_check_carries_performers_still_missing_an_avatar(self):
+ """资料处理不跑的日子,缺头像的存量女优跟着定时拉取补(ADR-0097)。试过的不再带。"""
+ from peach import avatar_followup
+ from peach.followups import Attempts, attempts_root
+
+ with self.contract.database.write_transaction() as connection:
+ entity_id = connection.execute(
+ "INSERT INTO entity(kind,canonical_name,normalized_name,created_at,updated_at)"
+ " VALUES('performer','二の宮すずか','二の宮すずか',?,?)",
+ ("2026-09-22T00:00:00Z", "2026-09-22T00:00:00Z")).lastrowid
+ connection.execute(
+ "INSERT INTO asset(id,location,path,name,medium,code,size)"
+ " VALUES(9001,'R:','R:\\media\\NHDTB-557.mp4','NHDTB-557.mp4','video','NHDTB-557',1)")
+ connection.execute(
+ "INSERT INTO asset_entity(asset_id,entity_id,role,source)"
+ " VALUES(9001,?,'performer','test')", (entity_id,))
+ key = avatar_followup.followup_key("performer", entity_id)
+ self.assertIn(key, [item["key"] for item in self._check(automatic=True)["followups"]])
+ with self.contract.database.read_connection() as connection:
+ current = avatar_followup.fingerprint(connection, entity_id)
+ Attempts(attempts_root(self.contract.candidate_root)).record(key, current, "图库 6 张认不准")
+ self.assertNotIn(key, [item["key"] for item in self._check(automatic=True)["followups"]])
+
def test_an_unknown_action_is_refused(self):
with self.assertRaises(ValueError):
dispatch_api_post(self.contract, "/api/feeds/discovery",