feat: topic message swr cache (#10886)

feat: add topic message swr cache
This commit is contained in:
Shinji-Li
2025-12-23 10:31:57 +08:00
committed by arvinxx
parent d9de7a547e
commit 613a404bf5
2 changed files with 6 additions and 5 deletions
@@ -3,7 +3,7 @@ import type { ConversationContext, UIChatMessage } from '@lobechat/types';
import type { SWRResponse } from 'swr';
import type { StateCreator } from 'zustand/vanilla';
import { useClientDataSWR } from '@/libs/swr';
import { useClientDataSWRWithSync } from '@/libs/swr';
import { messageService } from '@/services/message';
import type { Store as ConversationStore } from '../../action';
@@ -105,14 +105,14 @@ export const dataSlice: StateCreator<
// This is used when external messages are provided (e.g., creating new thread)
const shouldFetch = !skipFetch && !!context.agentId;
return useClientDataSWR<UIChatMessage[]>(
return useClientDataSWRWithSync<UIChatMessage[]>(
shouldFetch ? ['CONVERSATION_FETCH_MESSAGES', context] : null,
async ([, key]: [string, ConversationContext]) => {
return messageService.getMessages(key as any);
async () => {
return messageService.getMessages(context as any);
},
{
onSuccess: (data) => {
onData: (data) => {
if (!data) return;
// Parse messages using conversation-flow
+1
View File
@@ -276,6 +276,7 @@ const SWR_CACHEABLE_PATTERNS = [
// Chat page data
'SWR_USE_FETCH_TOPIC', // Topic list (cached per agentId/groupId)
'fetchGroupDetail', // Group detail (cached per groupId)
'CONVERSATION_FETCH_MESSAGES', // Messages (cached per agentId/topicId)
];
/**