From 46d84a0cdcce7f7042365df8f06222977bcf1a83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A5=80=E6=A2=A6?= <3501646051@qq.com> Date: Sun, 5 Apr 2026 13:41:38 +0800 Subject: [PATCH] chore: remove scripts/ dir; move settings maintenance to script/settings_maintain.py Avoids path autocomplete clash with script/start.bat under script/ Made-with: Cursor --- script/settings_maintain.py | 44 +++++++++++++++++++++++++++ scripts/apply_settings_maintenance.py | 35 --------------------- scripts/db_optimize_settings.sql | 14 --------- 3 files changed, 44 insertions(+), 49 deletions(-) create mode 100644 script/settings_maintain.py delete mode 100644 scripts/apply_settings_maintenance.py delete mode 100644 scripts/db_optimize_settings.sql diff --git a/script/settings_maintain.py b/script/settings_maintain.py new file mode 100644 index 0000000..ff428a1 --- /dev/null +++ b/script/settings_maintain.py @@ -0,0 +1,44 @@ +"""维护 SQLite settings 表:删除废弃键并写入推荐验证参数。 + +请在项目根目录执行(与 start.bat 同级的上一级): + python script/settings_maintain.py + +改库后需重启应用或在 WebUI 保存一次设置,WorkerPool / Validator 才会重载并发与超时。 +""" +import asyncio +import os +import sys + +_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +if _ROOT not in sys.path: + sys.path.insert(0, _ROOT) + +_SETTINGS_MAINTENANCE_SQL = """ +DELETE FROM settings WHERE key = 'crawl_timeout'; +DELETE FROM settings WHERE key = 'max_retries'; +INSERT INTO settings (key, value, updated_at) VALUES ('validation_timeout', '6', CURRENT_TIMESTAMP) +ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated_at = CURRENT_TIMESTAMP; +INSERT INTO settings (key, value, updated_at) VALUES ('default_concurrency', '120', CURRENT_TIMESTAMP) +ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated_at = CURRENT_TIMESTAMP; +""" + + +async def _run() -> None: + import aiosqlite + + from app.core.db import DB_PATH, ensure_db_dir + + ensure_db_dir() + if not os.path.isfile(DB_PATH): + print(f"数据库不存在,跳过: {DB_PATH}") + return + + async with aiosqlite.connect(DB_PATH) as db: + await db.executescript(_SETTINGS_MAINTENANCE_SQL) + await db.commit() + print(f"已执行设置维护: {DB_PATH}") + print("请重启应用或在 WebUI 保存一次设置以使并发/超时生效。") + + +if __name__ == "__main__": + asyncio.run(_run()) diff --git a/scripts/apply_settings_maintenance.py b/scripts/apply_settings_maintenance.py deleted file mode 100644 index 9d007df..0000000 --- a/scripts/apply_settings_maintenance.py +++ /dev/null @@ -1,35 +0,0 @@ -"""对 SQLite settings 表执行维护 SQL(见 db_optimize_settings.sql)。 - -使用当前应用配置的数据库路径(app.core.db.DB_PATH)。pytest 使用 PROXYPOOL_DB_PATH -指向 db/proxies.test.sqlite,勿在生产库路径上误跑测试夹具。 -""" -import asyncio -import os -import sys - -# 保证可 import app -sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) - - -async def main() -> None: - from app.core.db import DB_PATH, ensure_db_dir - import aiosqlite - - sql_path = os.path.join(os.path.dirname(__file__), "db_optimize_settings.sql") - with open(sql_path, encoding="utf-8") as f: - script = f.read() - - ensure_db_dir() - if not os.path.isfile(DB_PATH): - print(f"数据库不存在,跳过: {DB_PATH}") - return - - async with aiosqlite.connect(DB_PATH) as db: - await db.executescript(script) - await db.commit() - print(f"已执行设置维护: {DB_PATH}") - print("请重启应用或在 WebUI 保存一次设置以使并发/超时生效。") - - -if __name__ == "__main__": - asyncio.run(main()) diff --git a/scripts/db_optimize_settings.sql b/scripts/db_optimize_settings.sql deleted file mode 100644 index adddcc0..0000000 --- a/scripts/db_optimize_settings.sql +++ /dev/null @@ -1,14 +0,0 @@ --- ProxyPool:设置表维护(负优化清理 + 推荐验证参数) --- 用法:在停服或确认无并发写入时执行;或运行 python scripts/apply_settings_maintenance.py --- 注意:改库后需「重启应用」或在 WebUI「保存设置」才会让运行中的 WorkerPool / Validator 重载并发与超时。 - --- 废弃键 -DELETE FROM settings WHERE key = 'crawl_timeout'; -DELETE FROM settings WHERE key = 'max_retries'; - --- 推荐验证参数(可按机器与网络再调大 default_concurrency) -INSERT INTO settings (key, value, updated_at) VALUES ('validation_timeout', '6', CURRENT_TIMESTAMP) -ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated_at = CURRENT_TIMESTAMP; - -INSERT INTO settings (key, value, updated_at) VALUES ('default_concurrency', '120', CURRENT_TIMESTAMP) -ON CONFLICT(key) DO UPDATE SET value = excluded.value, updated_at = CURRENT_TIMESTAMP;