refactor(db): 重构数据库交互为异步模式
为了提升性能并与项目整体的异步架构保持一致,对核心数据库交互模块进行了异步化重构。 主要修改内容包括: - 将 `PermissionManager` 中的所有数据库操作从同步改为异步,以避免阻塞事件循环。 - 使用 `async_sessionmaker` 和 `async with session` 替代原有的同步会话管理。 - 将 SQLAlchemy 查询语法更新为异步兼容的 `await session.execute(select(...))` 模式。 - 相应地,调用链中依赖数据库操作的多个方法也已更新为 `async` 函数。
This commit is contained in:
@@ -660,7 +660,7 @@ class DefaultReplyer:
|
||||
duration = end_time - start_time
|
||||
return name, result, duration
|
||||
|
||||
def build_s4u_chat_history_prompts(
|
||||
async def build_s4u_chat_history_prompts(
|
||||
self, message_list_before_now: List[Dict[str, Any]], target_user_id: str, sender: str
|
||||
) -> Tuple[str, str]:
|
||||
"""
|
||||
@@ -692,7 +692,7 @@ class DefaultReplyer:
|
||||
all_dialogue_prompt = ""
|
||||
if message_list_before_now:
|
||||
latest_25_msgs = message_list_before_now[-int(global_config.chat.max_context_size) :]
|
||||
all_dialogue_prompt_str = build_readable_messages(
|
||||
all_dialogue_prompt_str = await build_readable_messages(
|
||||
latest_25_msgs,
|
||||
replace_bot_name=True,
|
||||
timestamp_mode="normal",
|
||||
@@ -716,7 +716,7 @@ class DefaultReplyer:
|
||||
else:
|
||||
core_dialogue_list = core_dialogue_list[-int(global_config.chat.max_context_size * 2) :] # 限制消息数量
|
||||
|
||||
core_dialogue_prompt_str = build_readable_messages(
|
||||
core_dialogue_prompt_str = await build_readable_messages(
|
||||
core_dialogue_list,
|
||||
replace_bot_name=True,
|
||||
merge_messages=False,
|
||||
|
||||
Reference in New Issue
Block a user