perf(memory): 优化记忆系统数据库操作并修复并发问题
将消息记忆次数的更新方式从单次写入重构为批量更新,在记忆构建任务结束时统一执行,大幅减少数据库写入次数,显著提升性能。 此外,为 `HippocampusManager` 添加了异步锁,以防止记忆巩固和遗忘操作并发执行时产生竞争条件。同时,增加了节点去重逻辑,在插入数据库前检查重复的概念,确保数据一致性。
This commit is contained in:
committed by
Windpicker-owo
parent
58626d00fa
commit
7e52b2f546
@@ -1689,11 +1689,7 @@ class HippocampusManager:
|
||||
if not self._initialized:
|
||||
raise RuntimeError("HippocampusManager 尚未初始化,请先调用 initialize 方法")
|
||||
async with self._db_lock:
|
||||
if self._hippocampus and self._hippocampus.parahippocampal_gyrus:
|
||||
return await self._hippocampus.parahippocampal_gyrus.operation_forget_topic(percentage)
|
||||
else:
|
||||
logger.warning("海马体或海马旁回未初始化,跳过本次记忆遗忘。")
|
||||
return None
|
||||
return await self._hippocampus.parahippocampal_gyrus.operation_forget_topic(percentage)
|
||||
|
||||
async def consolidate_memory(self):
|
||||
"""整合记忆的公共接口"""
|
||||
@@ -1701,11 +1697,7 @@ class HippocampusManager:
|
||||
raise RuntimeError("HippocampusManager 尚未初始化,请先调用 initialize 方法")
|
||||
# 使用 operation_build_memory 方法来整合记忆
|
||||
async with self._db_lock:
|
||||
if self._hippocampus and self._hippocampus.parahippocampal_gyrus:
|
||||
return await self._hippocampus.parahippocampal_gyrus.operation_build_memory()
|
||||
else:
|
||||
logger.warning("海马体或海马旁回未初始化,跳过本次记忆整合。")
|
||||
return None
|
||||
return await self._hippocampus.parahippocampal_gyrus.operation_build_memory()
|
||||
|
||||
async def get_memory_from_text(
|
||||
self,
|
||||
|
||||
@@ -384,7 +384,7 @@ class NoticeHandler:
|
||||
message_id=raw_message.get("message_id",""),
|
||||
emoji_id=like_emoji_id
|
||||
)
|
||||
seg_data = Seg(type="text",data=f"{user_name}使用Emoji表情{QQ_FACE.get(like_emoji_id,"")}回复了你的消息[{target_message_text}]")
|
||||
seg_data = Seg(type="text",data=f"{user_name}使用Emoji表情{QQ_FACE.get(like_emoji_id, '')}回复了你的消息[{target_message_text}]")
|
||||
return seg_data, user_info
|
||||
|
||||
async def handle_group_upload_notify(self, raw_message: dict, group_id: int, user_id: int, self_id: int):
|
||||
|
||||
Reference in New Issue
Block a user