refactor(chat): 移除 ChatStream 的历史消息自动加载功能

移除 ChatStream 初始化时的 `_load_history_messages()` 调用,改为按需异步加载历史消息。这解决了启动时阻塞事件循环的问题,并提高了聊天流初始化的性能。

主要变更:
- 删除 `ChatStream._load_history_messages()` 方法及相关代码
- 将多个模块中的同步数据库查询函数改为异步版本
- 修复相关调用处的异步调用方式
- 优化图片描述查询的错误处理

BREAKING CHANGE: `get_raw_msg_before_timestamp_with_chat` 和相关消息查询函数现在改为异步操作,需要调用处使用 await
This commit is contained in:
Windpicker-owo
2025-09-28 21:31:49 +08:00
parent c31fd02daf
commit ae0c2704d1
12 changed files with 27 additions and 151 deletions

View File

@@ -263,9 +263,9 @@ def get_messages_before_time(timestamp: float, limit: int = 0, filter_mai: bool
return get_raw_msg_before_timestamp(timestamp, limit)
def get_messages_before_time_in_chat(
async def get_messages_before_time_in_chat(
chat_id: str, timestamp: float, limit: int = 0, filter_mai: bool = False
) -> Coroutine[Any, Any, list[dict[str, Any]]]:
) -> list[dict[str, Any]]:
"""
获取指定聊天中指定时间戳之前的消息
@@ -290,8 +290,8 @@ def get_messages_before_time_in_chat(
if not isinstance(chat_id, str):
raise ValueError("chat_id 必须是字符串类型")
if filter_mai:
return filter_mai_messages(get_raw_msg_before_timestamp_with_chat(chat_id, timestamp, limit))
return get_raw_msg_before_timestamp_with_chat(chat_id, timestamp, limit)
return await filter_mai_messages(await get_raw_msg_before_timestamp_with_chat(chat_id, timestamp, limit))
return await get_raw_msg_before_timestamp_with_chat(chat_id, timestamp, limit)
def get_messages_before_time_for_users(timestamp: float, person_ids: List[str], limit: int = 0) -> Coroutine[