Merge pull request #3004 from InfinityPacer/feature/module

This commit is contained in:
jxxghp
2024-11-05 07:03:49 +08:00
committed by GitHub
2 changed files with 11 additions and 7 deletions
+10 -6
View File
@@ -65,8 +65,8 @@ class ConfigModel(BaseModel):
DB_POOL_RECYCLE: int = 1800 DB_POOL_RECYCLE: int = 1800
# 数据库连接池获取连接的超时时间(秒),默认 60 秒 # 数据库连接池获取连接的超时时间(秒),默认 60 秒
DB_POOL_TIMEOUT: int = 60 DB_POOL_TIMEOUT: int = 60
# 数据库连接池最大溢出连接数,默认 10 # 数据库连接池最大溢出连接数,默认 500
DB_MAX_OVERFLOW: int = 10 DB_MAX_OVERFLOW: int = 500
# SQLite 的 busy_timeout 参数,默认为 60 秒 # SQLite 的 busy_timeout 参数,默认为 60 秒
DB_TIMEOUT: int = 60 DB_TIMEOUT: int = 60
# 配置文件目录 # 配置文件目录
@@ -360,15 +360,19 @@ class Settings(BaseSettings, ConfigModel):
try: try:
field = self.__fields__[key] field = self.__fields__[key]
original_value = getattr(self, key)
if field.name == "API_TOKEN": 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: 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) field.default, key)
# 如果没有抛出异常,则统一使用 converted_value 进行更新 # 如果没有抛出异常,则统一使用 converted_value 进行更新
if needs_update or str(value) != str(converted_value): if needs_update or str(value) != str(converted_value):
setattr(self, key, converted_value) success, message = self.update_env_config(field, original_value, converted_value)
return self.update_env_config(field, value, converted_value) # 仅成功更新配置时,才更新内存
if success:
setattr(self, key, converted_value)
return success, message
return True, "" return True, ""
except Exception as e: except Exception as e:
return False, str(e) return False, str(e)
+1 -1
View File
@@ -12,7 +12,7 @@ LOG_LEVEL=INFO
# 数据库连接池的大小,可适当降低如20-50以减少I/O压力 # 数据库连接池的大小,可适当降低如20-50以减少I/O压力
DB_POOL_SIZE=100 DB_POOL_SIZE=100
# 数据库连接池最大溢出连接数,可适当降低如0以减少I/O压力 # 数据库连接池最大溢出连接数,可适当降低如0以减少I/O压力
DB_MAX_OVERFLOW=10 DB_MAX_OVERFLOW=500
# SQLite 的 busy_timeout 参数,可适当增加如180以减少锁定错误 # SQLite 的 busy_timeout 参数,可适当增加如180以减少锁定错误
DB_TIMEOUT=60 DB_TIMEOUT=60
# 【*】超级管理员,设置后一但重启将固化到数据库中,修改将无效(初始化超级管理员密码仅会生成一次,请在日志中查看并自行登录系统修改) # 【*】超级管理员,设置后一但重启将固化到数据库中,修改将无效(初始化超级管理员密码仅会生成一次,请在日志中查看并自行登录系统修改)