refactor: 清理 13 处生产死代码

为什么:用 AST 级引用分析(而非文本 grep——同名符号会互相掩盖)确认这些
符号全项目零引用。文本 grep 查不出的原因是它们都有「活着的同名兄弟」:

services/downloads.py(共 6 个,93 行)
  _parse_cookie_str / _global_music_u / _vip_name / _detect_vip /
  _admin_client / _user_client
  —— 活的是 core.media.parse_cookie_str、web/routers/music.py、account.py 的版本
  随之失效的 import:USER_COOKIE_FILE / GLOBAL_MUSIC_U_CACHE / VIP_PROBE_LOCK /
  account_info / detect_vip_by_probe / QRLoginClient

services/api_service.py
  APIResponse 类(29 行)—— web/response.py 才是活的响应封装

services/_shared.py
  _rate_ok —— 逐字复制 web.ratelimit.rate_ok

core/utils.py
  safe_int / safe_console_print —— 活的是 web/request_utils.safe_int

core/repo.py
  all_settings / get_user_by_name —— auth_system.get_user_by_name 才是活的

core/db.py / web/auth_state.py / web/request_utils.py
  execute_many / _safe_register_credits + secrets_rand / dedup_ids

结果:生产代码死代码候选 13 → 0(余下 118 个全是 pytest 测试函数,属正常)。
This commit is contained in:
snowy-yang committed 2026-09-26 18:54:11 +08:00
1 parent 445c16c329
commit 0569b50737
8 files changed
+10 -217

No files matched your search

-17
View File
@@ -7,8 +7,6 @@
import secrets
import time
import auth_system as auth
# ---- 登录失败锁定(按用户名维度,10 分钟窗口内 >=5 次临时锁定)----
_LOGIN_FAILS: dict = {}
_LOGIN_FAIL_SWEEP_TS = 0.0
@@ -119,16 +117,6 @@ def _login_fail_locked_log_once(username: str) -> bool:
return True
def _safe_register_credits() -> int:
"""注册赠送次数(settings.register_credits,默认 3)。
防呆:损坏回退默认;<0 一律按 0——设为 -1 会经 create_user 造出"不限次"新号。"""
try:
credits = int(auth.get_setting('register_credits', str(auth.DEFAULT_REGISTER_CREDITS)) or 0)
except (TypeError, ValueError):
return auth.DEFAULT_REGISTER_CREDITS
return max(0, credits)
_SEND_CODE_IP = {}
@@ -165,8 +153,3 @@ def re_username_ok(username: str) -> bool:
return bool(_re.fullmatch(r'[A-Za-z0-9_\u4e00-\u9fa5]{3,20}', username)) and \
not _re.match(r'^_+$', username) and not username.startswith('_') and not username.endswith('_') \
and username.lower() not in _RESERVED_USERNAMES
def secrets_rand() -> int:
import secrets as _s
return _s.randbelow(900000) + 100000
-16
View File
@@ -65,19 +65,3 @@ def cookies() -> dict[str, str]:
"""全局账号 Cookie(管理员 cookie.txt)。"""
import music_api
return music_api.load_cookies()
def dedup_ids(raw_ids: Any, transform=extract_id) -> list[str]:
"""ID 列表去重(保持首次出现顺序):与 Flask 侧「提取→去重」计费口径一致。"""
if isinstance(raw_ids, str):
raw_list = raw_ids.split(',')
else:
raw_list = [str(x) for x in (raw_ids or [])]
out: list[str] = []
seen: set[str] = set()
for x in raw_list:
s = str(transform(x) or '').strip()
if s and s not in seen:
seen.add(s)
out.append(s)
return out