feat(config): add live slow-sql threshold setting
This commit is contained in:
15
database.py
15
database.py
@@ -120,7 +120,7 @@ config = get_config()
|
||||
DB_FILE = config.DB_FILE
|
||||
|
||||
# 数据库版本 (用于迁移管理)
|
||||
DB_VERSION = 19
|
||||
DB_VERSION = 20
|
||||
|
||||
|
||||
# ==================== 系统配置缓存(P1 / O-03) ====================
|
||||
@@ -183,6 +183,12 @@ def init_database():
|
||||
|
||||
ensure_default_admin()
|
||||
|
||||
try:
|
||||
config_value = get_system_config()
|
||||
db_pool.configure_slow_query_runtime(threshold_ms=config_value.get("db_slow_query_ms"))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def migrate_database():
|
||||
"""数据库迁移(对外保留接口)。"""
|
||||
@@ -240,6 +246,7 @@ def update_system_config(
|
||||
kdocs_admin_notify_email=None,
|
||||
kdocs_row_start=None,
|
||||
kdocs_row_end=None,
|
||||
db_slow_query_ms=None,
|
||||
):
|
||||
"""更新系统配置(写入后立即失效缓存)。"""
|
||||
ok = _update_system_config(
|
||||
@@ -268,7 +275,13 @@ def update_system_config(
|
||||
kdocs_admin_notify_email=kdocs_admin_notify_email,
|
||||
kdocs_row_start=kdocs_row_start,
|
||||
kdocs_row_end=kdocs_row_end,
|
||||
db_slow_query_ms=db_slow_query_ms,
|
||||
)
|
||||
if ok:
|
||||
invalidate_system_config_cache()
|
||||
try:
|
||||
latest_config = get_system_config()
|
||||
db_pool.configure_slow_query_runtime(threshold_ms=latest_config.get("db_slow_query_ms"))
|
||||
except Exception:
|
||||
pass
|
||||
return ok
|
||||
|
||||
Reference in New Issue
Block a user