优化缓存命中

This commit is contained in:
2026-07-29 09:48:44 +08:00
parent 7247b1d832
commit 886df10775
3 changed files with 23 additions and 18 deletions

View File

@@ -7,7 +7,7 @@ const { broadcastToRoom } = require('./ws');
// 对话历史(内存)
const conversationHistory = new Map();
function getHistory(roomId) { if (!conversationHistory.has(roomId)) conversationHistory.set(roomId, []); return conversationHistory.get(roomId); }
function addToHistory(roomId, role, content) { const h = getHistory(roomId); h.push({ role, content }); if (h.length > 60) conversationHistory.set(roomId, h.slice(-40)); }
function addToHistory(roomId, role, content) { var h = getHistory(roomId); h.push({ role: role, content: content }); if (h.length > 60) conversationHistory.set(roomId, h.slice(-30)); }
// 待处理操作
const pendingActions = new Map();