mirror of
https://github.com/lobehub/lobe-chat.git
synced 2026-06-14 11:40:07 +00:00
✨ feat: topic message swr cache (#10886)
feat: add topic message swr cache
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user