refactor(chat): 将消息获取相关函数重构为异步

将 `chat_message_builder` 中的多个同步消息获取函数(如 `get_raw_msg_by_timestamp`)及其调用全部修改为异步函数。这统一了数据库查询的异步模式,提高了代码一致性和可维护性。

主要改动包括:
- 将 `chat_message_builder.py` 中的数据库查询函数标记为 `async` 并使用 `await`。
- 更新了 `message_api.py`、`mood_manager.py` 和 `qzone_service.py` 中对这些函数的调用,以适应异步接口。
- 调整了 `message_api.py` 中的函数签名和返回类型提示,以反映异步特性。
This commit is contained in:
minecraft1024a
2025-10-02 17:32:02 +08:00
parent a7acd98023
commit d5627b0661
4 changed files with 65 additions and 59 deletions

View File

@@ -103,7 +103,7 @@ class ChatMood:
logger.debug(
f"{self.log_prefix} 更新情绪状态,感兴趣度: {interested_rate:.2f}, 更新概率: {update_probability:.2f}"
)
message_list_before_now = get_raw_msg_by_timestamp_with_chat_inclusive(
message_list_before_now = await get_raw_msg_by_timestamp_with_chat_inclusive(
chat_id=self.chat_id,
timestamp_start=self.last_change_time,
timestamp_end=message_time,
@@ -152,7 +152,7 @@ class ChatMood:
async def regress_mood(self):
message_time = time.time()
message_list_before_now = get_raw_msg_by_timestamp_with_chat_inclusive(
message_list_before_now = await get_raw_msg_by_timestamp_with_chat_inclusive(
chat_id=self.chat_id,
timestamp_start=self.last_change_time,
timestamp_end=message_time,