Skip to content

armgit / peach

Public Imported from GitHub
0

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

fix(web): 番号目录那一类复核队列改为现算,不再读 CSV 快照

longmeidao5636cadd28a1
diff --git a/scripts/audit_code_creators.py b/scripts/audit_code_creators.py
index 5624bb0ed..b24ef0112 100644
--- a/scripts/audit_code_creators.py
+++ b/scripts/audit_code_creators.py
@@ -2,8 +2,8 @@
# -*- coding: utf-8 -*-
r"""番号目录被投影成创作者的清理器。
-判定与清理在 `peach.code_creators`:复核页按同一套判据现算队列,有文件级证据的那批
-由自动落库处理,本脚本是同一件事的命令行入口,另外产出可复核、可重放的 CSV。
+判定与清理在 `peach.code_creators`,复核页按同一套判据现算队列。本脚本是写这一步的
+唯一入口:有文件级证据的那批由 `--apply` 带备份清掉,另外产出可复核、可重放的 CSV。
默认只产出复核 CSV,`--apply` 才写 ledger 且必须给 `--backup`。
"""
diff --git a/src/peach/code_creators.py b/src/peach/code_creators.py
index 070b3d1bb..1496fdfd3 100644
--- a/src/peach/code_creators.py
+++ b/src/peach/code_creators.py
@@ -16,8 +16,12 @@ r"""被投影成创作者的番号目录名:判定与清理。
因此判定不看名字形态,只看文件级证据:目录内的媒体文件名必须解析出同一个番号。
账号目录里的文件是作品标题,解析不出番号,天然不会命中;pixiv 行的 path 是 URL,
-直接排除。证据成立的那批不进人工队列——界面能给出的信息不比这条判据多,而它判的是
-「这个名字是不是番号」,不是「这部片归谁」。证据不成立的一律留人工。
+直接排除。证据成立的那批由 `scripts/audit_code_creators.py --apply` 带备份清理,
+证据不成立的留人工。
+
+`collect` 的输出就是复核页那一类的队列:这一类现算,不读候选文件。判据的输入只有账本
+本身,没有需要留存的外部证据,而按 CSV 快照摆队列会摆出早已不存在的实体——实测一份
+44 行的快照里 27 行属于此类,点进去无事可做。
"""
from __future__ import annotations
diff --git a/src/peach/web_review.py b/src/peach/web_review.py
index 626e35ff3..1b5cb9199 100644
--- a/src/peach/web_review.py
+++ b/src/peach/web_review.py
@@ -26,6 +26,7 @@ from .catalog_rules import (
same_release_code,
superseded_taste_tags,
)
+from .code_creators import collect
from .config import GENERATED_DIR
from .entities import (
canonicalize_entity_name,
@@ -78,7 +79,6 @@ CANDIDATE_PREFIX = {
"performer_avatars": "performer-avatar-candidate-",
# 这三类此前只落在 CSV 里没有界面入口,复核负担等于被丢回给用户去翻文件。
"western_identity": "babepedia-candidates",
- "code_creators": "code-creator-review",
"cover_sources": "cover-fetch-log",
"fc2_markings": "fc2-candidate-log",
"fc2_similarity": "fc2-similarity-candidate-",
@@ -97,12 +97,17 @@ CANDIDATE_KEY = {
"studio_logos": "studio",
"performer_avatars": "entity_id",
"western_identity": "entity_id",
- "code_creators": "entity_id",
"cover_sources": "code",
"fc2_markings": "code",
"fc2_similarity": "pair_key",
"video_endcards": "candidate_key",
}
+#: 队列现算、不读候选文件的类别,取行的函数见 `LIVE_CATEGORY_ROWS`。判据的输入就是
+#: 账本本身,没有需要留存的外部证据,所以 CSV 只是某一次跑脚本时的快照:实测那份
+#: 44 行里有 27 行的实体早已不在库里,点进去无事可做,真正该看的只有 24 条。
+LIVE_CATEGORIES = ("code_creators",)
+#: 复核页的类别全集。页面的 tab 次序由 `app.js` 的 `REVIEW_LABELS` 定,与这里无关。
+REVIEW_CATEGORIES = (*CANDIDATE_PREFIX, *LIVE_CATEGORIES)
#: 复核卡片上那张脸属于哪种实体。页面按同一张表决定 `/entity-image` 的 kind
#: (`app.js` 的 `ENTITY_REVIEW_CATEGORIES`),两边必须逐字一致:这边判成 creator、
#: 页面按 performer 取图,就是标志说有图而请求照样 404。不在表里的类别没有这个位置。
@@ -431,10 +436,32 @@ def _fold_genre_decisions(field: str, candidate: dict, decided: dict[str, str |
if not genres_in_warning(warning)]}
-def _review_rows(contract: ReviewContract, category: str) -> tuple[list[dict], str | None, int]:
+def _code_creator_rows(connection) -> list[dict]:
+ """番号目录被投影成创作者的队列,按 `peach.code_creators` 的判据现算。"""
+ rows = [dict(row) for row in collect(connection)]
+ for row in rows:
+ row["item_key"] = str(row["entity_id"])
+ return rows
+
+
+#: 现算类别取行的函数。写成表而不是分支:`_review_rows` 已经顶着复杂度基线,
+#: 每加一类都往里塞一个 if 的话,最先撑不住的是那个函数而不是这张表。
+LIVE_CATEGORY_ROWS = {"code_creators": _code_creator_rows}
+
+
+def _queue_rows(contract: ReviewContract, category: str,
+ connection) -> tuple[list[dict], str | None, int]:
+ """这一类队列的原始行与来源说明:现算类别问账本,其余读候选文件。"""
+ live = LIVE_CATEGORY_ROWS.get(category)
+ if live:
+ return live(connection), "ledger", 0
rows, source, skipped = read_candidates(category, contract.candidate_root)
- rows = [row for row in rows if _needs_review(category, row)]
+ return [row for row in rows if _needs_review(category, row)], source, skipped
+
+
+def _review_rows(contract: ReviewContract, category: str) -> tuple[list[dict], str | None, int]:
with contract.read_connection() as connection:
+ rows, source, skipped = _queue_rows(contract, category, connection)
decisions = {
row["item_key"]: dict(row) for row in connection.execute(
"SELECT item_key,status,note,updated_at FROM review_decision WHERE category=?",
@@ -964,7 +991,7 @@ def q_review(contract: ReviewContract):
row["asset_preview_url"] = ""
failures = _pending_first(failures)
sections, sources, skipped = {}, {}, {}
- for category in CANDIDATE_PREFIX:
+ for category in REVIEW_CATEGORIES:
rows, source, dropped = _review_rows(contract, category)
sections[category] = rows
sources[category] = source
diff --git a/tests/test_complexity_ratchet.py b/tests/test_complexity_ratchet.py
index c5b529d93..e6758aab2 100644
--- a/tests/test_complexity_ratchet.py
+++ b/tests/test_complexity_ratchet.py
@@ -29,8 +29,8 @@ BASELINE: dict[str, int] = {
"src/peach/web_batch.py:q_ads": 85,
"scripts/scrape_codes.py:_scrape": 77,
"scripts/localize_performer_names.py:collect": 64,
- "src/peach/web_review.py:_review_rows": 61,
"src/peach/web_resource_sync.py:_resource_orphan_plan": 60,
+ "src/peach/web_review.py:_review_rows": 59,
"src/peach/fanbox.py:normalize_fanbox_post": 59,
"src/peach/web_follow.py:q_follow": 52,
"scripts/merge_duplicate_identities.py:collect": 50,
diff --git a/tests/test_web_review.py b/tests/test_web_review.py
index e78285535..772ad6362 100644
--- a/tests/test_web_review.py
+++ b/tests/test_web_review.py
@@ -1472,17 +1472,46 @@ class ReviewQueueTests(unittest.TestCase):
})
self.assertEqual(result["applied_assets"], 0)
- def test_code_creator_candidates_reach_the_review_page(self):
- fields = ["entity_id", "creator", "verdict", "identity", "assets",
- "sample_path", "code_action", "reason"]
- self._csv("code-creator-review.csv", fields, [
- {"entity_id": "6869", "creator": "banbi_555", "verdict": "存疑",
- "identity": "BANBI-555", "assets": "69", "sample_path": "A:/x.mp4",
- "code_action": "", "reason": "名字像番号,但目录内没有同番号文件"}])
+ def _code_creator(self, entity_id, name, assets):
+ con = sqlite3.connect(self.db_path)
+ con.execute("INSERT INTO entity(id,kind,canonical_name,normalized_name,"
+ "created_at,updated_at) VALUES(?,'creator',?,?,'2026-01-01','2026-01-01')",
+ (entity_id, name, name.casefold()))
+ for asset_id, asset_name, path in assets:
+ con.execute("INSERT INTO asset(id,location,path,name,medium,creator) "
+ "VALUES(?,'local',?,?,'video',?)", (asset_id, path, asset_name, name))
+ con.execute("INSERT INTO asset_entity(asset_id,entity_id,role,source,confidence) "
+ "VALUES(?,?,'creator','legacy:asset',1.0)", (asset_id, entity_id))
+ con.commit(); con.close()
+
+ def test_code_creator_queue_is_computed_from_the_ledger(self):
+ """这一类没有候选文件,队列按当前账本现算。
+
+ 读 CSV 那份是跑脚本当时的快照:44 行里 27 行的实体后来被清掉了,点进去无事
+ 可做,而真正该看的只有 24 条。判据的输入本来就只有账本,没有要留存的外部证据。
+ """
+ self._code_creator(6869, "banbi_555", [
+ (101, "18歳Eカップ彼氏持ち美女.mp4", r"A:\Pack From Shared\pen\banbi_555\18歳.mp4")])
rows = rm_review.q_review(self.contract)["sections"]["code_creators"]
- self.assertEqual(rows[0]["item_key"], "6869")
+ self.assertEqual([row["item_key"] for row in rows], ["6869"])
+ self.assertEqual(rows[0]["verdict"], "存疑")
self.assertIn("没有同番号文件", rows[0]["reason"])
+ def test_a_cleaned_up_creator_leaves_the_queue_on_its_own(self):
+ """清理过的行不该靠重跑脚本刷 CSV 才消失。"""
+ self._code_creator(6870, "HD-abp-758", [
+ (102, "HD-abp-758.mp4", r"B:\云下载\HD-abp-758\HD-abp-758.mp4")])
+ self.assertEqual(
+ [row["item_key"] for row in
+ rm_review.q_review(self.contract)["sections"]["code_creators"]], ["6870"])
+
+ con = sqlite3.connect(self.db_path)
+ con.execute("DELETE FROM asset_entity WHERE entity_id=6870")
+ con.execute("DELETE FROM entity WHERE id=6870")
+ con.commit(); con.close()
+ self.assertEqual(
+ rm_review.q_review(self.contract)["counts"]["code_creators"], 0)
+
class PerformerAvatarApplyTests(ReviewQueueTests):
"""批准人物头像候选必须真的把图装上。