refactor(chat): 将用户引用处理从同步改为异步,优化性能

This commit is contained in:
Windpicker-owo
2025-11-03 23:11:49 +08:00
parent 5ba79de0e7
commit 914fe59a10
4 changed files with 56 additions and 24 deletions

View File

@@ -47,8 +47,9 @@ def replace_user_references_sync(
# 检查是否是机器人自己
if replace_bot_name and user_id == global_config.bot.qq_account:
return f"{global_config.bot.nickname}(你)"
person_id = PersonInfoManager.get_person_id(platform, user_id)
return person_info_manager.get_value(person_id, "person_name") or user_id # type: ignore
# 同步函数中无法使用异步的 get_value直接返回 user_id
# 建议调用方使用 replace_user_references_async 以获取完整的用户名
return user_id
name_resolver = default_resolver

View File

@@ -1090,9 +1090,6 @@ class Prompt:
Returns:
str: 格式化后的关系信息字符串,或在失败时返回空字符串。
"""
if not global_config.affinity_flow.enable_relationship_tracking:
return ""
from src.person_info.relationship_fetcher import relationship_fetcher_manager
relationship_fetcher = relationship_fetcher_manager.get_fetcher(chat_id)