每连接冗余计算与日志降级

提示词模板结果按设备 id 缓存复用、声纹未配置和 mcp 配置文件缺失两条提示从警告降到调试,让每条新连接少跑几百毫秒的模板渲染、少两次同步日志。
This commit is contained in:
hrz 2026-10-14 23:05:15 +08:00
parent 4f1cb98503
commit 597ab5f415
3 changed files with 10 additions and 3 deletions

View file

@ -781,7 +781,7 @@ class ConnectionHandler:
self.voiceprint_provider = voiceprint_provider
self.logger.bind(tag=TAG).info("声纹识别功能已在连接时动态启用")
else:
self.logger.bind(tag=TAG).warning("声纹识别功能启用但配置不完整")
self.logger.bind(tag=TAG).debug("声纹识别功能启用但配置不完整")
else:
self.logger.bind(tag=TAG).info("声纹识别功能未启用")
except Exception as e:

View file

@ -24,7 +24,7 @@ class ServerMCPManager:
self.config_path = get_project_dir() + "data/.mcp_server_settings.json"
if not os.path.exists(self.config_path):
self.config_path = ""
logger.bind(tag=TAG).warning(
logger.bind(tag=TAG).debug(
f"请检查mcp服务配置文件:data/.mcp_server_settings.json"
)
self.clients: Dict[str, ServerMCPClient] = {}

View file

@ -253,6 +253,13 @@ class PromptManager:
if not self.base_prompt_template:
return user_prompt
device_cache_key = f"device_prompt:{device_id}"
cached_prompt = self.cache_manager.get(
self.CacheType.DEVICE_PROMPT, device_cache_key
)
if cached_prompt is not None:
return cached_prompt
try:
# 获取最新的时间信息(不缓存)
today_date, today_weekday, lunar_date = self._get_current_time_info()
@ -305,7 +312,7 @@ class PromptManager:
self.cache_manager.set(
self.CacheType.DEVICE_PROMPT, device_cache_key, enhanced_prompt
)
self.logger.bind(tag=TAG).info(
self.logger.bind(tag=TAG).debug(
f"构建增强提示词成功,长度: {len(enhanced_prompt)}"
)
return enhanced_prompt