From fee04c0d259aff5eb4bed75c2054ed230d9e3dc0 Mon Sep 17 00:00:00 2001 From: Windpicker-owo <3431391539@qq.com> Date: Sun, 5 Oct 2025 03:24:28 +0800 Subject: [PATCH] =?UTF-8?q?perf(interest):=20=E5=A2=9E=E5=8A=A0=E5=85=B4?= =?UTF-8?q?=E8=B6=A3=E5=80=BC=E8=AE=A1=E7=AE=97=E8=B6=85=E6=97=B6=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E5=B9=B6=E4=BC=98=E5=8C=96=E6=97=A5=E5=BF=97=E8=AE=B0?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将兴趣值计算的默认超时时间从0.5秒增加到2.0秒,以减少因计算时间较长导致的超时情况。同时优化了超时日志记录,使用warning级别并显示具体的超时时间,使问题排查更加清晰。 --- src/chat/interest_system/interest_manager.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/chat/interest_system/interest_manager.py b/src/chat/interest_system/interest_manager.py index b0d4d6e8b..f415c4248 100644 --- a/src/chat/interest_system/interest_manager.py +++ b/src/chat/interest_system/interest_manager.py @@ -98,7 +98,7 @@ class InterestManager: logger.error(f"注册兴趣值计算组件失败: {e}", exc_info=True) return False - async def calculate_interest(self, message: "DatabaseMessages", timeout: float = 0.5) -> InterestCalculationResult: + async def calculate_interest(self, message: "DatabaseMessages", timeout: float = 2.0) -> InterestCalculationResult: """计算消息兴趣值 Args: @@ -126,14 +126,14 @@ class InterestManager: return result except asyncio.TimeoutError: # 超时返回默认结果,但计算仍在后台继续 - logger.debug(f"兴趣值计算超时,消息 {getattr(message, 'message_id', '')} 将使用默认值") + logger.warning(f"兴趣值计算超时 ({timeout}s),消息 {getattr(message, 'message_id', '')} 使用默认兴趣值 0.5") return InterestCalculationResult( success=True, message_id=getattr(message, 'message_id', ''), - interest_value=0.5, # 默认中等兴趣值 + interest_value=0.5, # 固定默认兴趣值 should_reply=False, should_act=False, - error_message="计算超时,使用默认值" + error_message=f"计算超时({timeout}s),使用默认值" ) except Exception as e: # 发生异常,返回默认结果