Skip to content

armgit / peach

Public Imported from GitHub
0

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

refactor(core): 删掉零引用的死符号与空生命周期钩子

longmeidao52005bc42d63
diff --git a/src/peach/api.py b/src/peach/api.py
index 736852977..87ff60f9d 100644
--- a/src/peach/api.py
+++ b/src/peach/api.py
@@ -236,8 +236,6 @@ def create_app(
@asynccontextmanager
async def lifespan(_app: FastAPI):
- if sync is not None:
- sync.start()
follow_scheduler.start()
if mdns is not None:
try:
@@ -254,8 +252,6 @@ def create_app(
contract.stop_background_jobs()
if mdns is not None:
await asyncio.to_thread(mdns.stop)
- if sync is not None:
- await asyncio.to_thread(sync.stop)
http_transport.close()
hls_plan_executor.shutdown(wait=False, cancel_futures=True)
diff --git a/src/peach/catalog_rules.py b/src/peach/catalog_rules.py
index ec5be9883..8b7707d62 100644
--- a/src/peach/catalog_rules.py
+++ b/src/peach/catalog_rules.py
@@ -66,7 +66,6 @@ POSITION_TAGS = {
_CODE_STUDIO = re.compile(r"^[A-Z]{2,8}-\d{2,5}$")
_CODE_AMATEUR = re.compile(r"^\d{3}[A-Z]{2,6}-\d{2,5}$")
-_CODE_FC2 = re.compile(r"^FC2-PPV-\d{5,}$")
_CODE_DATE = re.compile(r"^\d{6}-\d{2,4}$")
_MEDIA_EXTENSION = re.compile(
r"\.(?:mp4|mkv|avi|wmv|mov|m4v|webm|ts|m2ts|mts|mpg|mpeg|flv|rm|rmvb|iso)$",
diff --git a/src/peach/config.py b/src/peach/config.py
index 611407a28..be900022f 100644
--- a/src/peach/config.py
+++ b/src/peach/config.py
@@ -49,8 +49,6 @@ SOURCES_DIR = DATA_ROOT / "sources"
STATE_DIR = DATA_ROOT / "state"
SECRETS_DIR = DATA_ROOT / "secrets"
LOG_DIR = DATA_ROOT / "logs"
-ARCHIVE_DIR = DATA_ROOT / "archive"
-INBOX_DIR = DATA_ROOT / "inbox"
TOOLS_DIR = DATA_ROOT / "tools"
REVIEW_DIR = DATA_ROOT / "review"
FFMPEG_DIR = TOOLS_DIR / "ffmpeg"
diff --git a/src/peach/face_detect.py b/src/peach/face_detect.py
index 8588833c6..3bb8373e4 100644
--- a/src/peach/face_detect.py
+++ b/src/peach/face_detect.py
@@ -36,7 +36,6 @@ MODEL_URL = (
"models/face_detection_yunet/face_detection_yunet_2023mar.onnx"
)
MODEL_SHA256 = "8f2383e4dd3cfbb4553ea8718107fc0423210dc964f9f4280604804ed2552fa4"
-MODEL_BYTES = 232589
MODEL_PATH = TOOLS_DIR / "yunet" / "face_detection_yunet_2023mar.onnx"
#: 低于这个分数的检出不算数。YuNet 会给出置信度,不必再靠「落在左半边就是假阳性」
diff --git a/src/peach/metadata.py b/src/peach/metadata.py
index 9154ee7f9..79cf829bf 100644
--- a/src/peach/metadata.py
+++ b/src/peach/metadata.py
@@ -166,10 +166,6 @@ def collapse_repeated_phrase(value: str) -> tuple[str, bool]:
return cleaned, cleaned != original
-def safe_entity_name(value: str) -> str:
- return canonicalize_entity_name("performer", value)
-
-
def normalized_performers(raw: object) -> tuple[list[dict], list[str]]:
performers: list[dict] = []
warnings: list[str] = []
diff --git a/src/peach/platform.py b/src/peach/platform.py
index 122595d0b..9c4a57828 100644
--- a/src/peach/platform.py
+++ b/src/peach/platform.py
@@ -124,21 +124,3 @@ def translate_roots(roots) -> tuple[Path, ...]:
return tuple(path for path in translated if not is_unmapped(path))
-def media_root_status(roots) -> tuple[dict[str, object], ...]:
- """每个声明来源的可达性;`/api/index` 靠它决定要不要把本地筛选置灰。"""
- status: list[dict[str, object]] = []
- for root in roots:
- raw = os.fspath(root)
- path = translate_ledger_path(raw)
- mapped = not is_unmapped(path)
- status.append(
- {
- "declared": raw,
- "resolved": str(path) if mapped else None,
- "mapped": mapped,
- "online": bool(mapped and path.is_dir()),
- }
- )
- return tuple(status)
-
-
diff --git a/src/peach/providers.py b/src/peach/providers.py
index 1643d30a6..f84a348fd 100644
--- a/src/peach/providers.py
+++ b/src/peach/providers.py
@@ -7,7 +7,7 @@ import threading
import time
from dataclasses import asdict, dataclass
from enum import Enum
-from typing import Callable, Protocol
+from typing import Callable
import httpx
@@ -173,20 +173,3 @@ def default_registry(
note="Personal-local experimental adapter; Peach never reads Claude credentials.",
))
return registry
-
-
-class InferenceProvider(Protocol):
- name: str
-
- def health(self) -> dict: ...
- def list_models(self) -> list[dict]: ...
- def complete(self, request: dict) -> dict: ...
-
-
-class AgentProvider(Protocol):
- name: str
-
- def health(self) -> dict: ...
- def start(self, request: dict) -> dict: ...
- def resume(self, thread_id: str, request: dict) -> dict: ...
- def cancel(self, thread_id: str) -> None: ...
diff --git a/src/peach/sync.py b/src/peach/sync.py
index cb390cf46..a79d8339a 100644
--- a/src/peach/sync.py
+++ b/src/peach/sync.py
@@ -409,11 +409,6 @@ class LedgerSync:
with_digest=False)
write_marker(self.local, Marker(generation, self.device, stamp, 0, 0))
- # ── 生命周期 ────────────────────────────────────────────────────────────
- def startup(self) -> SyncPlan:
- """兼容旧调用:启动只观察,不再复制。"""
- return self.observe()
-
def observe(self) -> SyncPlan:
"""只读刷新当前角色与同步状态,不碰 DB 或 marker。"""
decision = plan(self.local, self.shared)
@@ -477,11 +472,3 @@ class LedgerSync:
return "conflict"
self.status = decision.action
return decision.action
-
- def start(self) -> None:
- """服务生命周期不再启动跨机同步线程。"""
- return None
-
- def stop(self) -> None:
- """没有后台同步线程,服务退出也不写任何共享状态。"""
- return None
diff --git a/src/peach/taste_history.py b/src/peach/taste_history.py
index 3065a827d..1deb63003 100644
--- a/src/peach/taste_history.py
+++ b/src/peach/taste_history.py
@@ -147,14 +147,6 @@ def _iso_from_unix_microseconds(value: int | float) -> str:
return datetime.fromtimestamp(float(value) / 1_000_000, UTC).isoformat()
-def _iso_from_chrome(value: int | float) -> str:
- return (datetime(1601, 1, 1, tzinfo=UTC) + timedelta(microseconds=float(value))).isoformat()
-
-
-def _iso_from_safari(value: int | float) -> str:
- return (datetime(2001, 1, 1, tzinfo=UTC) + timedelta(seconds=float(value))).isoformat()
-
-
def _read_visits(snapshot: Path, _browser: str | None = None) -> list[HistoryVisit]:
"""Use browserexport's maintained schema adapters and keep Peach's private DTO.
diff --git a/src/peach/web_contract.py b/src/peach/web_contract.py
index 5c49a617c..b52fde7d1 100644
--- a/src/peach/web_contract.py
+++ b/src/peach/web_contract.py
@@ -15,10 +15,9 @@ import shutil
import threading
import time
import uuid
-from concurrent.futures import ThreadPoolExecutor
from datetime import UTC, datetime, timedelta
-from pathlib import Path, PurePosixPath, PureWindowsPath
-from typing import Callable, Sequence
+from pathlib import Path, PureWindowsPath
+from typing import Sequence
from urllib.parse import quote, urlsplit
from .config import (
diff --git a/tests/test_sync.py b/tests/test_sync.py
index 2d95e2650..11c50b906 100644
--- a/tests/test_sync.py
+++ b/tests/test_sync.py
@@ -386,16 +386,17 @@ class LedgerSyncTests(unittest.TestCase):
self.assertEqual(writer_device(self.local, self.shared), "win")
self.assertFalse(sync.read_only)
- def test_service_stop_never_pushes_local_changes(self):
- make_db(self.local, 2)
- make_db(self.shared, 2)
- write_marker(self.local, Marker(7, "mac", "", 0, 0))
- write_marker(self.shared, Marker(7, "mac", "", 0, 0))
- sync = self.sync("mac")
- sync.observe()
- make_db(self.local, 1)
- sync.stop()
- self.assertEqual(count(self.shared), 2)
+ def test_the_service_lifecycle_has_no_hook_that_could_push(self):
+ """停机不回写靠的是「没有这个钩子」,不是钩子里写了 return None。
+
+ 原来 `LedgerSync` 有一对空的 `start`/`stop` 和一个只转发的 `startup`,
+ `api` 的 lifespan 照样一进一出地调用它们——读代码的人得跳进 `sync.py`
+ 才能确认那几行什么都不做,而「服务退出会不会把本地改动推上去」正是这个
+ 模块最不该靠猜的问题。回写只能由托盘/CLI 的 `ledger-sync` 显式触发。
+ """
+ for name in ("start", "stop", "startup"):
+ self.assertFalse(hasattr(LedgerSync, name),
+ f"LedgerSync.{name} 又回来了:回写必须留在显式命令里")
if __name__ == "__main__":