From 4d3aa0faf35545607d78fc6e7687490dc06825e1 Mon Sep 17 00:00:00 2001 From: InfinityPacer <160988576+InfinityPacer@users.noreply.github.com> Date: Tue, 5 Nov 2024 00:48:02 +0800 Subject: [PATCH 1/2] fix(config): update in-memory setting only on env update --- app/core/config.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/core/config.py b/app/core/config.py index eca5c9c3..1c9b6ec0 100644 --- a/app/core/config.py +++ b/app/core/config.py @@ -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) From 8afaa683cc71a9a14f4b94302217afb5414f7cc8 Mon Sep 17 00:00:00 2001 From: InfinityPacer <160988576+InfinityPacer@users.noreply.github.com> Date: Tue, 5 Nov 2024 00:48:22 +0800 Subject: [PATCH 2/2] fix(config): update DB_MAX_OVERFLOW to 500 --- app/core/config.py | 4 ++-- config/app.env | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/core/config.py b/app/core/config.py index 1c9b6ec0..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 # 配置文件目录 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 # 【*】超级管理员,设置后一但重启将固化到数据库中,修改将无效(初始化超级管理员密码仅会生成一次,请在日志中查看并自行登录系统修改)