优化缓存命中

This commit is contained in:
2026-07-29 10:23:01 +08:00
parent de2de85e58
commit 6a768ef146
3 changed files with 13 additions and 2 deletions

View File

@@ -168,8 +168,8 @@ function handleAIResult(aiResult, roomId, username, originalText, attachments) {
} }
if (aiResult.action === 'query') { if (aiResult.action === 'query') {
storeAndBroadcastText(roomId, '小财', '🔍 正在查询采购数据,请稍候...'); broadcastToRoom(roomId, { type: 'query_pending', text: '🔍 正在查询采购数据,请稍候...' });
const purchaseData = db.prepare('SELECT item, amount, payment_method, status FROM purchases WHERE room_id = ? ORDER BY created_at DESC').all(roomId).map(p => p.item + ' ' + p.amount + ' ' + (p.payment_method||'') + ' ' + p.status).join('\n'); const purchaseData = db.prepare('SELECT item, amount, payment_method, status, created_at FROM purchases WHERE room_id = ? ORDER BY created_at DESC').all(roomId).map(p => p.created_at + ' ' + p.item + ' ' + p.amount + ' ' + (p.payment_method||'') + ' ' + p.status).join('\n');
const summaryPrompt = '根据以下采购记录,用自然语言回答用户查询"' + originalText + '"。采购记录:\n' + (purchaseData || '暂无记录'); const summaryPrompt = '根据以下采购记录,用自然语言回答用户查询"' + originalText + '"。采购记录:\n' + (purchaseData || '暂无记录');
callDeepSeekForSummary(summaryPrompt, username).then(reply => { storeAndBroadcastText(roomId, '小财', reply); addToHistory(roomId, 'assistant', reply); }); callDeepSeekForSummary(summaryPrompt, username).then(reply => { storeAndBroadcastText(roomId, '小财', reply); addToHistory(roomId, 'assistant', reply); });
return; return;

View File

@@ -170,6 +170,15 @@ function clearTempBubble() {
tempEls.forEach(function(el) { el.remove(); }); tempEls.forEach(function(el) { el.remove(); });
} }
function showTempBubble(text) {
clearTempBubble();
var tempId = 'temp_' + Date.now();
var tempMsg = { id: tempId, user: '小财', text: text, attachments: [], timestamp: '', isTemp: true };
Store.messageCache.push(tempMsg);
messagesContainer.insertAdjacentHTML('beforeend', renderMessageHTML(tempMsg));
scrollToBottom();
}
// 双指缩放 + 拖拽 // 双指缩放 + 拖拽
function initPinchZoom(img) { function initPinchZoom(img) {
var scale = 1, startDist = 0, startScale = 1; var scale = 1, startDist = 0, startScale = 1;

View File

@@ -19,6 +19,8 @@ function initWebSocket() {
const room = Store.rooms.find(r => r.id === data.room_preview.room_id); const room = Store.rooms.find(r => r.id === data.room_preview.room_id);
if (room) { room.last_message = data.room_preview.last_message; room.last_time = data.room_preview.last_time; renderChatList(); } if (room) { room.last_message = data.room_preview.last_message; room.last_time = data.room_preview.last_time; renderChatList(); }
} }
} else if (data.type === 'query_pending') {
if (Store.currentRoom === roomId) showTempBubble(data.text);
} else if (data.type === 'purchase_updated') { } else if (data.type === 'purchase_updated') {
if (Store.currentRoom) loadPurchases(); if (Store.currentRoom) loadPurchases();
updateSummaryPreview(); updateSummaryPreview();