🎉 项目优化与Bug修复完整版
✨ 主要优化成果: - 修复Unicode字符编码问题(Windows跨平台兼容性) - 安装wkhtmltoimage,截图功能完全修复 - 智能延迟优化(api_browser.py) - 线程池资源泄漏修复(tasks.py) - HTML解析缓存机制 - 二分搜索算法优化(kdocs_uploader.py) - 自适应资源配置(browser_pool_worker.py) 🐛 Bug修复: - 解决截图失败问题 - 修复管理员密码设置 - 解决应用启动编码错误 📚 新增文档: - BUG_REPORT.md - 完整bug分析报告 - PERFORMANCE_ANALYSIS_REPORT.md - 性能优化分析 - LINUX_DEPLOYMENT_ANALYSIS.md - Linux部署指南 - SCREENSHOT_FIX_SUCCESS.md - 截图功能修复记录 - INSTALL_WKHTMLTOIMAGE.md - 安装指南 - OPTIMIZATION_FIXES_SUMMARY.md - 优化总结 🚀 功能验证: - Flask应用正常运行(51233端口) - 数据库、截图线程池、API预热正常 - 管理员登录:admin/admin123 - 健康检查API:http://127.0.0.1:51233/health 💡 技术改进: - 智能延迟算法(自适应调整) - LRU缓存策略 - 线程池资源管理优化 - 二分搜索算法(O(log n) vs O(n)) - 自适应资源管理 🎯 项目现在稳定运行,可部署到Linux环境
This commit is contained in:
@@ -104,29 +104,29 @@ def _migrate_to_v1(conn):
|
||||
|
||||
if "schedule_weekdays" not in columns:
|
||||
cursor.execute('ALTER TABLE system_config ADD COLUMN schedule_weekdays TEXT DEFAULT "1,2,3,4,5,6,7"')
|
||||
print(" ✓ 添加 schedule_weekdays 字段")
|
||||
print(" [OK] 添加 schedule_weekdays 字段")
|
||||
|
||||
if "max_screenshot_concurrent" not in columns:
|
||||
cursor.execute("ALTER TABLE system_config ADD COLUMN max_screenshot_concurrent INTEGER DEFAULT 3")
|
||||
print(" ✓ 添加 max_screenshot_concurrent 字段")
|
||||
print(" [OK] 添加 max_screenshot_concurrent 字段")
|
||||
if "max_concurrent_per_account" not in columns:
|
||||
cursor.execute("ALTER TABLE system_config ADD COLUMN max_concurrent_per_account INTEGER DEFAULT 1")
|
||||
print(" ✓ 添加 max_concurrent_per_account 字段")
|
||||
print(" [OK] 添加 max_concurrent_per_account 字段")
|
||||
if "auto_approve_enabled" not in columns:
|
||||
cursor.execute("ALTER TABLE system_config ADD COLUMN auto_approve_enabled INTEGER DEFAULT 0")
|
||||
print(" ✓ 添加 auto_approve_enabled 字段")
|
||||
print(" [OK] 添加 auto_approve_enabled 字段")
|
||||
if "auto_approve_hourly_limit" not in columns:
|
||||
cursor.execute("ALTER TABLE system_config ADD COLUMN auto_approve_hourly_limit INTEGER DEFAULT 10")
|
||||
print(" ✓ 添加 auto_approve_hourly_limit 字段")
|
||||
print(" [OK] 添加 auto_approve_hourly_limit 字段")
|
||||
if "auto_approve_vip_days" not in columns:
|
||||
cursor.execute("ALTER TABLE system_config ADD COLUMN auto_approve_vip_days INTEGER DEFAULT 7")
|
||||
print(" ✓ 添加 auto_approve_vip_days 字段")
|
||||
print(" [OK] 添加 auto_approve_vip_days 字段")
|
||||
|
||||
cursor.execute("PRAGMA table_info(task_logs)")
|
||||
columns = [col[1] for col in cursor.fetchall()]
|
||||
if "duration" not in columns:
|
||||
cursor.execute("ALTER TABLE task_logs ADD COLUMN duration INTEGER")
|
||||
print(" ✓ 添加 duration 字段到 task_logs")
|
||||
print(" [OK] 添加 duration 字段到 task_logs")
|
||||
|
||||
conn.commit()
|
||||
|
||||
@@ -140,19 +140,19 @@ def _migrate_to_v2(conn):
|
||||
|
||||
if "proxy_enabled" not in columns:
|
||||
cursor.execute("ALTER TABLE system_config ADD COLUMN proxy_enabled INTEGER DEFAULT 0")
|
||||
print(" ✓ 添加 proxy_enabled 字段")
|
||||
print(" [OK] 添加 proxy_enabled 字段")
|
||||
|
||||
if "proxy_api_url" not in columns:
|
||||
cursor.execute('ALTER TABLE system_config ADD COLUMN proxy_api_url TEXT DEFAULT ""')
|
||||
print(" ✓ 添加 proxy_api_url 字段")
|
||||
print(" [OK] 添加 proxy_api_url 字段")
|
||||
|
||||
if "proxy_expire_minutes" not in columns:
|
||||
cursor.execute("ALTER TABLE system_config ADD COLUMN proxy_expire_minutes INTEGER DEFAULT 3")
|
||||
print(" ✓ 添加 proxy_expire_minutes 字段")
|
||||
print(" [OK] 添加 proxy_expire_minutes 字段")
|
||||
|
||||
if "enable_screenshot" not in columns:
|
||||
cursor.execute("ALTER TABLE system_config ADD COLUMN enable_screenshot INTEGER DEFAULT 1")
|
||||
print(" ✓ 添加 enable_screenshot 字段")
|
||||
print(" [OK] 添加 enable_screenshot 字段")
|
||||
|
||||
conn.commit()
|
||||
|
||||
@@ -166,15 +166,15 @@ def _migrate_to_v3(conn):
|
||||
|
||||
if "status" not in columns:
|
||||
cursor.execute('ALTER TABLE accounts ADD COLUMN status TEXT DEFAULT "active"')
|
||||
print(" ✓ 添加 accounts.status 字段 (账号状态)")
|
||||
print(" [OK] 添加 accounts.status 字段 (账号状态)")
|
||||
|
||||
if "login_fail_count" not in columns:
|
||||
cursor.execute("ALTER TABLE accounts ADD COLUMN login_fail_count INTEGER DEFAULT 0")
|
||||
print(" ✓ 添加 accounts.login_fail_count 字段 (登录失败计数)")
|
||||
print(" [OK] 添加 accounts.login_fail_count 字段 (登录失败计数)")
|
||||
|
||||
if "last_login_error" not in columns:
|
||||
cursor.execute("ALTER TABLE accounts ADD COLUMN last_login_error TEXT")
|
||||
print(" ✓ 添加 accounts.last_login_error 字段 (最后登录错误)")
|
||||
print(" [OK] 添加 accounts.last_login_error 字段 (最后登录错误)")
|
||||
|
||||
conn.commit()
|
||||
|
||||
@@ -188,7 +188,7 @@ def _migrate_to_v4(conn):
|
||||
|
||||
if "source" not in columns:
|
||||
cursor.execute('ALTER TABLE task_logs ADD COLUMN source TEXT DEFAULT "manual"')
|
||||
print(" ✓ 添加 task_logs.source 字段 (任务来源: manual/scheduled/immediate)")
|
||||
print(" [OK] 添加 task_logs.source 字段 (任务来源: manual/scheduled/immediate)")
|
||||
|
||||
conn.commit()
|
||||
|
||||
@@ -219,7 +219,7 @@ def _migrate_to_v5(conn):
|
||||
)
|
||||
"""
|
||||
)
|
||||
print(" ✓ 创建 user_schedules 表 (用户定时任务)")
|
||||
print(" [OK] 创建 user_schedules 表 (用户定时任务)")
|
||||
|
||||
cursor.execute(
|
||||
"""
|
||||
@@ -243,12 +243,12 @@ def _migrate_to_v5(conn):
|
||||
)
|
||||
"""
|
||||
)
|
||||
print(" ✓ 创建 schedule_execution_logs 表 (定时任务执行日志)")
|
||||
print(" [OK] 创建 schedule_execution_logs 表 (定时任务执行日志)")
|
||||
|
||||
cursor.execute("CREATE INDEX IF NOT EXISTS idx_user_schedules_user_id ON user_schedules(user_id)")
|
||||
cursor.execute("CREATE INDEX IF NOT EXISTS idx_user_schedules_enabled ON user_schedules(enabled)")
|
||||
cursor.execute("CREATE INDEX IF NOT EXISTS idx_user_schedules_next_run ON user_schedules(next_run_at)")
|
||||
print(" ✓ 创建 user_schedules 表索引")
|
||||
print(" [OK] 创建 user_schedules 表索引")
|
||||
|
||||
conn.commit()
|
||||
|
||||
@@ -271,10 +271,10 @@ def _migrate_to_v6(conn):
|
||||
)
|
||||
"""
|
||||
)
|
||||
print(" ✓ 创建 announcements 表 (公告)")
|
||||
print(" [OK] 创建 announcements 表 (公告)")
|
||||
cursor.execute("CREATE INDEX IF NOT EXISTS idx_announcements_active ON announcements(is_active)")
|
||||
cursor.execute("CREATE INDEX IF NOT EXISTS idx_announcements_created_at ON announcements(created_at)")
|
||||
print(" ✓ 创建 announcements 表索引")
|
||||
print(" [OK] 创建 announcements 表索引")
|
||||
|
||||
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='announcement_dismissals'")
|
||||
if not cursor.fetchone():
|
||||
@@ -290,9 +290,9 @@ def _migrate_to_v6(conn):
|
||||
)
|
||||
"""
|
||||
)
|
||||
print(" ✓ 创建 announcement_dismissals 表 (公告永久关闭记录)")
|
||||
print(" [OK] 创建 announcement_dismissals 表 (公告永久关闭记录)")
|
||||
cursor.execute("CREATE INDEX IF NOT EXISTS idx_announcement_dismissals_user ON announcement_dismissals(user_id)")
|
||||
print(" ✓ 创建 announcement_dismissals 表索引")
|
||||
print(" [OK] 创建 announcement_dismissals 表索引")
|
||||
|
||||
conn.commit()
|
||||
|
||||
@@ -351,7 +351,7 @@ def _migrate_to_v7(conn):
|
||||
shift_utc_to_cst(table, col)
|
||||
|
||||
conn.commit()
|
||||
print(" ✓ 时区迁移:历史UTC时间已转换为北京时间")
|
||||
print(" [OK] 时区迁移:历史UTC时间已转换为北京时间")
|
||||
|
||||
|
||||
def _migrate_to_v8(conn):
|
||||
@@ -363,11 +363,11 @@ def _migrate_to_v8(conn):
|
||||
columns = [col[1] for col in cursor.fetchall()]
|
||||
if "random_delay" not in columns:
|
||||
cursor.execute("ALTER TABLE user_schedules ADD COLUMN random_delay INTEGER DEFAULT 0")
|
||||
print(" ✓ 添加 user_schedules.random_delay 字段")
|
||||
print(" [OK] 添加 user_schedules.random_delay 字段")
|
||||
|
||||
if "next_run_at" not in columns:
|
||||
cursor.execute("ALTER TABLE user_schedules ADD COLUMN next_run_at TIMESTAMP")
|
||||
print(" ✓ 添加 user_schedules.next_run_at 字段")
|
||||
print(" [OK] 添加 user_schedules.next_run_at 字段")
|
||||
|
||||
cursor.execute("CREATE INDEX IF NOT EXISTS idx_user_schedules_next_run ON user_schedules(next_run_at)")
|
||||
conn.commit()
|
||||
@@ -420,7 +420,7 @@ def _migrate_to_v8(conn):
|
||||
|
||||
conn.commit()
|
||||
if fixed:
|
||||
print(f" ✓ 已为 {fixed} 条启用定时任务补算 next_run_at")
|
||||
print(f" [OK] 已为 {fixed} 条启用定时任务补算 next_run_at")
|
||||
except Exception as e:
|
||||
# 迁移过程中不阻断主流程;上线后由 worker 兜底补算
|
||||
print(f" ⚠ v8 迁移补算 next_run_at 失败: {e}")
|
||||
@@ -441,15 +441,15 @@ def _migrate_to_v9(conn):
|
||||
changed = False
|
||||
if "register_verify_enabled" not in columns:
|
||||
cursor.execute("ALTER TABLE email_settings ADD COLUMN register_verify_enabled INTEGER DEFAULT 0")
|
||||
print(" ✓ 添加 email_settings.register_verify_enabled 字段")
|
||||
print(" [OK] 添加 email_settings.register_verify_enabled 字段")
|
||||
changed = True
|
||||
if "base_url" not in columns:
|
||||
cursor.execute("ALTER TABLE email_settings ADD COLUMN base_url TEXT DEFAULT ''")
|
||||
print(" ✓ 添加 email_settings.base_url 字段")
|
||||
print(" [OK] 添加 email_settings.base_url 字段")
|
||||
changed = True
|
||||
if "task_notify_enabled" not in columns:
|
||||
cursor.execute("ALTER TABLE email_settings ADD COLUMN task_notify_enabled INTEGER DEFAULT 0")
|
||||
print(" ✓ 添加 email_settings.task_notify_enabled 字段")
|
||||
print(" [OK] 添加 email_settings.task_notify_enabled 字段")
|
||||
changed = True
|
||||
|
||||
if changed:
|
||||
@@ -465,11 +465,11 @@ def _migrate_to_v10(conn):
|
||||
changed = False
|
||||
if "email_verified" not in columns:
|
||||
cursor.execute("ALTER TABLE users ADD COLUMN email_verified INTEGER DEFAULT 0")
|
||||
print(" ✓ 添加 users.email_verified 字段")
|
||||
print(" [OK] 添加 users.email_verified 字段")
|
||||
changed = True
|
||||
if "email_notify_enabled" not in columns:
|
||||
cursor.execute("ALTER TABLE users ADD COLUMN email_notify_enabled INTEGER DEFAULT 1")
|
||||
print(" ✓ 添加 users.email_notify_enabled 字段")
|
||||
print(" [OK] 添加 users.email_notify_enabled 字段")
|
||||
changed = True
|
||||
|
||||
if changed:
|
||||
@@ -495,7 +495,7 @@ def _migrate_to_v11(conn):
|
||||
conn.commit()
|
||||
|
||||
if updated:
|
||||
print(f" ✓ 已将 {updated} 个 pending 用户迁移为 approved")
|
||||
print(f" [OK] 已将 {updated} 个 pending 用户迁移为 approved")
|
||||
except sqlite3.OperationalError as e:
|
||||
print(f" ⚠️ v11 迁移跳过: {e}")
|
||||
|
||||
@@ -668,7 +668,7 @@ def _migrate_to_v15(conn):
|
||||
changed = False
|
||||
if "login_alert_enabled" not in columns:
|
||||
cursor.execute("ALTER TABLE email_settings ADD COLUMN login_alert_enabled INTEGER DEFAULT 1")
|
||||
print(" ✓ 添加 email_settings.login_alert_enabled 字段")
|
||||
print(" [OK] 添加 email_settings.login_alert_enabled 字段")
|
||||
changed = True
|
||||
|
||||
try:
|
||||
@@ -692,7 +692,7 @@ def _migrate_to_v16(conn):
|
||||
if "image_url" not in columns:
|
||||
cursor.execute("ALTER TABLE announcements ADD COLUMN image_url TEXT")
|
||||
conn.commit()
|
||||
print(" ✓ 添加 announcements.image_url 字段")
|
||||
print(" [OK] 添加 announcements.image_url 字段")
|
||||
|
||||
|
||||
def _migrate_to_v17(conn):
|
||||
@@ -716,7 +716,7 @@ def _migrate_to_v17(conn):
|
||||
for field, ddl in system_fields:
|
||||
if field not in columns:
|
||||
cursor.execute(f"ALTER TABLE system_config ADD COLUMN {field} {ddl}")
|
||||
print(f" ✓ 添加 system_config.{field} 字段")
|
||||
print(f" [OK] 添加 system_config.{field} 字段")
|
||||
|
||||
cursor.execute("PRAGMA table_info(users)")
|
||||
columns = [col[1] for col in cursor.fetchall()]
|
||||
@@ -728,7 +728,7 @@ def _migrate_to_v17(conn):
|
||||
for field, ddl in user_fields:
|
||||
if field not in columns:
|
||||
cursor.execute(f"ALTER TABLE users ADD COLUMN {field} {ddl}")
|
||||
print(f" ✓ 添加 users.{field} 字段")
|
||||
print(f" [OK] 添加 users.{field} 字段")
|
||||
|
||||
conn.commit()
|
||||
|
||||
@@ -742,10 +742,10 @@ def _migrate_to_v18(conn):
|
||||
|
||||
if "kdocs_row_start" not in columns:
|
||||
cursor.execute("ALTER TABLE system_config ADD COLUMN kdocs_row_start INTEGER DEFAULT 0")
|
||||
print(" ✓ 添加 system_config.kdocs_row_start 字段")
|
||||
print(" [OK] 添加 system_config.kdocs_row_start 字段")
|
||||
|
||||
if "kdocs_row_end" not in columns:
|
||||
cursor.execute("ALTER TABLE system_config ADD COLUMN kdocs_row_end INTEGER DEFAULT 0")
|
||||
print(" ✓ 添加 system_config.kdocs_row_end 字段")
|
||||
print(" [OK] 添加 system_config.kdocs_row_end 字段")
|
||||
|
||||
conn.commit()
|
||||
|
||||
Reference in New Issue
Block a user