diff --git a/app/core/config.py b/app/core/config.py index eca5c9c3..482b78e3 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -65,8 +65,8 @@ class ConfigModel(BaseModel): DB_POOL_RECYCLE: int = 1800 # 数据库连接池获取连接的超时时间(秒),默认 60 秒 DB_POOL_TIMEOUT: int = 60 - # 数据库连接池最大溢出连接数,默认 10 - DB_MAX_OVERFLOW: int = 10 + # 数据库连接池最大溢出连接数,默认 500 + DB_MAX_OVERFLOW: int = 500 # SQLite 的 busy_timeout 参数,默认为 60 秒 DB_TIMEOUT: int = 60 # 配置文件目录 @@ -360,15 +360,19 @@ class Settings(BaseSettings, ConfigModel): try: field = self.__fields__[key] + original_value = getattr(self, key) if field.name == "API_TOKEN": - converted_value, needs_update = self.validate_api_token(value, getattr(self, key)) + converted_value, needs_update = self.validate_api_token(value, original_value) else: - converted_value, needs_update = self.generic_type_converter(value, getattr(self, key), field.type_, + converted_value, needs_update = self.generic_type_converter(value, original_value, field.type_, field.default, key) # 如果没有抛出异常,则统一使用 converted_value 进行更新 if needs_update or str(value) != str(converted_value): - setattr(self, key, converted_value) - return self.update_env_config(field, value, converted_value) + success, message = self.update_env_config(field, original_value, converted_value) + # 仅成功更新配置时,才更新内存 + if success: + setattr(self, key, converted_value) + return success, message return True, "" except Exception as e: return False, str(e) diff --git a/config/app.env b/config/app.env index 417a987b..78ba50bf 100644 --- a/config/app.env +++ b/config/app.env @@ -12,7 +12,7 @@ LOG_LEVEL=INFO # 数据库连接池的大小,可适当降低如20-50以减少I/O压力 DB_POOL_SIZE=100 # 数据库连接池最大溢出连接数,可适当降低如0以减少I/O压力 -DB_MAX_OVERFLOW=10 +DB_MAX_OVERFLOW=500 # SQLite 的 busy_timeout 参数,可适当增加如180以减少锁定错误 DB_TIMEOUT=60 # 【*】超级管理员,设置后一但重启将固化到数据库中,修改将无效(初始化超级管理员密码仅会生成一次,请在日志中查看并自行登录系统修改)