refactor: 移除冗余文件并优化代码结构
- 删除多个不再使用的脚本和配置文件,包括 `auto_push.bat`, `check_and_fix_users.py`, `init.sql` 等。 - 新增 `git_push.bat` 和 `git_push.sh` 脚本以简化 Git 推送流程。 - 更新 `README.md` 以反映最新的功能和结构变化。 - 优化前端代码,添加新的页面和组件,提升用户体验。 此提交旨在清理项目结构并增强代码可维护性。
This commit is contained in:
@@ -26,18 +26,22 @@ class DatabaseManager:
|
||||
|
||||
# 根据数据库类型选择不同的连接参数
|
||||
if "mysql" in db_config["url"]:
|
||||
# MySQL配置 - 优化连接池
|
||||
# MySQL配置 - 优化连接池和重连机制
|
||||
self.engine = create_engine(
|
||||
db_config["url"],
|
||||
echo=db_config["echo"],
|
||||
pool_size=20, # 增加连接池大小
|
||||
max_overflow=30, # 增加溢出连接数
|
||||
pool_pre_ping=True,
|
||||
pool_recycle=1800, # 减少回收时间
|
||||
pool_timeout=30, # 连接池超时(秒)
|
||||
pool_size=10, # 连接池大小
|
||||
max_overflow=20, # 溢出连接数
|
||||
pool_pre_ping=True, # 连接前检查连接是否有效
|
||||
pool_recycle=3600, # 1小时后回收连接
|
||||
pool_timeout=60, # 连接池超时(秒)
|
||||
connect_args={
|
||||
"charset": "utf8mb4",
|
||||
"autocommit": False,
|
||||
"connect_timeout": 30, # 连接超时
|
||||
"read_timeout": 60, # 读取超时
|
||||
"write_timeout": 60, # 写入超时
|
||||
"max_allowed_packet": 64*1024*1024, # 64MB
|
||||
"connect_timeout": 30, # 连接超时(秒)- 适用于网络延迟较大的情况
|
||||
"read_timeout": 30, # 读取超时(秒)
|
||||
"write_timeout": 30, # 写入超时(秒)
|
||||
@@ -82,7 +86,32 @@ class DatabaseManager:
|
||||
logger.error(f"数据库操作失败: {e}")
|
||||
raise
|
||||
finally:
|
||||
session.close()
|
||||
try:
|
||||
session.close()
|
||||
except Exception as close_error:
|
||||
logger.warning(f"关闭数据库会话时出错: {close_error}")
|
||||
|
||||
def check_connection(self) -> bool:
|
||||
"""检查数据库连接是否正常"""
|
||||
try:
|
||||
with self.get_session() as session:
|
||||
session.execute(text("SELECT 1"))
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"数据库连接检查失败: {e}")
|
||||
return False
|
||||
|
||||
def reconnect(self) -> bool:
|
||||
"""重新连接数据库"""
|
||||
try:
|
||||
if self.engine:
|
||||
self.engine.dispose()
|
||||
self._initialize_database()
|
||||
logger.info("数据库重新连接成功")
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"数据库重新连接失败: {e}")
|
||||
return False
|
||||
|
||||
def get_session_direct(self) -> Session:
|
||||
"""直接获取数据库会话"""
|
||||
|
||||
Reference in New Issue
Block a user