refactor: inject Rust acceleration settings

This commit is contained in:
jxxghp
2026-08-23 01:37:08 +08:00
parent e63745f40b
commit d15c65b108
4 changed files with 19 additions and 8 deletions
+12 -2
View File
@@ -1,8 +1,9 @@
import importlib
import logging
from functools import lru_cache
from typing import List, Optional, Tuple
from app.runtime.config import settings
from app.application.configuration import get_runtime_settings
from app.runtime.log import logger, log_settings
try:
@@ -14,6 +15,15 @@ else:
_import_error = None
def _rust_accel_enabled() -> bool:
"""读取 Rust 开关快照,组合根未装配时回退旧 Settings。"""
try:
return bool(get_runtime_settings().get("RUST_ACCEL"))
except RuntimeError:
legacy_settings = importlib.import_module("app.runtime.config").settings
return bool(legacy_settings.RUST_ACCEL)
def is_available() -> bool:
"""
判断 Rust 扩展是否可用。
@@ -25,7 +35,7 @@ def is_config_enabled() -> bool:
"""
判断系统配置是否允许使用 Rust 加速。
"""
return bool(settings.RUST_ACCEL)
return _rust_accel_enabled()
def is_enabled() -> bool: