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:
@@ -308,8 +308,8 @@ class ImageManager:
|
||||
|
||||
async with get_db_session() as session:
|
||||
# 优先检查Images表中是否已有完整的描述
|
||||
existing_image = result = await session.execute(select(Images).where(Images.emoji_hash == image_hash))
|
||||
result.scalar()
|
||||
result = await session.execute(select(Images).where(Images.emoji_hash == image_hash))
|
||||
existing_image = result.scalar()
|
||||
if existing_image:
|
||||
# 更新计数
|
||||
if hasattr(existing_image, "count") and existing_image.count is not None:
|
||||
@@ -528,8 +528,8 @@ class ImageManager:
|
||||
image_bytes = base64.b64decode(image_base64)
|
||||
image_hash = hashlib.md5(image_bytes).hexdigest()
|
||||
async with get_db_session() as session:
|
||||
existing_image = result = await session.execute(select(Images).where(Images.emoji_hash == image_hash))
|
||||
result.scalar()
|
||||
result = await session.execute(select(Images).where(Images.emoji_hash == image_hash))
|
||||
existing_image = result.scalar()
|
||||
if existing_image:
|
||||
# 检查是否缺少必要字段,如果缺少则创建新记录
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user