This commit is contained in:
2026-01-08 18:46:14 +08:00
parent 472b1a0d5e
commit 4016c1e6eb
7 changed files with 2815 additions and 1470 deletions

View File

@@ -180,6 +180,33 @@ class ContextStore:
pass
self.memory_fallback.pop(chat_id, None)
async def clear_group_history(self, chat_id: str) -> None:
"""
清空群聊历史记录
同时清除 Redis 和本地文件中的群聊历史
"""
# 清除 Redis 中的群聊历史
if self._use_redis_for_group_history():
redis_cache = get_cache()
try:
key = f"group_history:{_safe_chat_id(chat_id)}"
redis_cache.delete(key)
logger.debug(f"[ContextStore] 已清除 Redis 群聊历史: {chat_id}")
except Exception as e:
logger.debug(f"[ContextStore] 清除 Redis 群聊历史失败: {e}")
# 清除本地文件中的群聊历史
history_file = self._get_history_file(chat_id)
if history_file and history_file.exists():
lock = self._get_history_lock(chat_id)
async with lock:
try:
history_file.unlink()
logger.debug(f"[ContextStore] 已清除本地群聊历史文件: {history_file}")
except Exception as e:
logger.debug(f"[ContextStore] 清除本地群聊历史文件失败: {e}")
# ------------------ 群聊 history ------------------
def _use_redis_for_group_history(self) -> bool: