perf(methods): 通过移除不必要的 self 参数优化方法签名
在包括 chat、plugin_system、schedule 和 mais4u 在内的多个模块中,消除冗余的实例引用。此次改动将无需访问实例状态的实用函数转换为静态方法,从而提升了内存效率,并使方法依赖关系更加清晰。
This commit is contained in:
@@ -926,7 +926,7 @@ class EntorhinalCortex:
|
||||
timestamp_start = target_timestamp
|
||||
timestamp_end = target_timestamp + time_window_seconds
|
||||
|
||||
if chosen_message := get_raw_msg_by_timestamp(
|
||||
if chosen_message := await get_raw_msg_by_timestamp(
|
||||
timestamp_start=timestamp_start,
|
||||
timestamp_end=timestamp_end,
|
||||
limit=1,
|
||||
@@ -934,7 +934,7 @@ class EntorhinalCortex:
|
||||
):
|
||||
chat_id: str = chosen_message[0].get("chat_id") # type: ignore
|
||||
|
||||
if messages := get_raw_msg_by_timestamp_with_chat(
|
||||
if messages := await get_raw_msg_by_timestamp_with_chat(
|
||||
timestamp_start=timestamp_start,
|
||||
timestamp_end=timestamp_end,
|
||||
limit=chat_size,
|
||||
|
||||
@@ -137,7 +137,8 @@ class AsyncMemoryQueue:
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
async def _handle_store_task(self, task: MemoryTask) -> Any:
|
||||
@staticmethod
|
||||
async def _handle_store_task(task: MemoryTask) -> Any:
|
||||
"""处理记忆存储任务"""
|
||||
# 这里需要根据具体的记忆系统来实现
|
||||
# 为了避免循环导入,这里使用延迟导入
|
||||
@@ -156,7 +157,8 @@ class AsyncMemoryQueue:
|
||||
logger.error(f"记忆存储失败: {e}")
|
||||
return False
|
||||
|
||||
async def _handle_retrieve_task(self, task: MemoryTask) -> Any:
|
||||
@staticmethod
|
||||
async def _handle_retrieve_task(task: MemoryTask) -> Any:
|
||||
"""处理记忆检索任务"""
|
||||
try:
|
||||
# 获取包装器实例
|
||||
@@ -173,7 +175,8 @@ class AsyncMemoryQueue:
|
||||
logger.error(f"记忆检索失败: {e}")
|
||||
return []
|
||||
|
||||
async def _handle_build_task(self, task: MemoryTask) -> Any:
|
||||
@staticmethod
|
||||
async def _handle_build_task(task: MemoryTask) -> Any:
|
||||
"""处理记忆构建任务(海马体系统)"""
|
||||
try:
|
||||
# 延迟导入避免循环依赖
|
||||
|
||||
@@ -106,7 +106,8 @@ class InstantMemory:
|
||||
else:
|
||||
logger.info(f"不需要记忆:{text}")
|
||||
|
||||
async def store_memory(self, memory_item: MemoryItem):
|
||||
@staticmethod
|
||||
async def store_memory(memory_item: MemoryItem):
|
||||
with get_db_session() as session:
|
||||
memory = Memory(
|
||||
memory_id=memory_item.memory_id,
|
||||
@@ -198,7 +199,8 @@ class InstantMemory:
|
||||
logger.error(f"获取记忆出现错误:{str(e)} {traceback.format_exc()}")
|
||||
return None
|
||||
|
||||
def _parse_time_range(self, time_str):
|
||||
@staticmethod
|
||||
def _parse_time_range(time_str):
|
||||
# sourcery skip: extract-duplicate-method, use-contextlib-suppress
|
||||
"""
|
||||
支持解析如下格式:
|
||||
|
||||
@@ -243,7 +243,8 @@ class VectorInstantMemoryV2:
|
||||
logger.error(f"查找相似消息失败: {e}")
|
||||
return []
|
||||
|
||||
def _format_time_ago(self, timestamp: float) -> str:
|
||||
@staticmethod
|
||||
def _format_time_ago(timestamp: float) -> str:
|
||||
"""格式化时间差显示"""
|
||||
if timestamp <= 0:
|
||||
return "未知时间"
|
||||
|
||||
Reference in New Issue
Block a user