From 11f42ad9ede8fb7323206d25ad221e1d102cf72d Mon Sep 17 00:00:00 2001 From: archer <545436317@qq.com> Date: Tue, 2 May 2023 14:18:43 +0800 Subject: [PATCH] perf: chat load --- src/pages/chat/components/SlideBar.tsx | 20 +++++++++++++++----- src/pages/chat/index.tsx | 11 +++++------ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/pages/chat/components/SlideBar.tsx b/src/pages/chat/components/SlideBar.tsx index fcbd5362e..470ed339f 100644 --- a/src/pages/chat/components/SlideBar.tsx +++ b/src/pages/chat/components/SlideBar.tsx @@ -50,11 +50,19 @@ const SlideBar = ({ const { isOpen: isOpenWx, onOpen: onOpenWx, onClose: onCloseWx } = useDisclosure(); const preChatId = useRef('chatId'); // 用于校验上一次chatId的情况,判断是否需要刷新历史记录 - const { isSuccess } = useQuery(['getMyModels'], getMyModels, { - cacheTime: 5 * 60 * 1000 + const { isSuccess, refetch: fetchMyModels } = useQuery(['getMyModels'], getMyModels, { + cacheTime: 5 * 60 * 1000, + enabled: false }); - const { data: collectionModels = [] } = useQuery([getCollectionModels], getCollectionModels); + const { data: collectionModels = [], refetch: fetchCollectionModels } = useQuery( + [getCollectionModels], + getCollectionModels, + { + cacheTime: 5 * 60 * 1000, + enabled: false + } + ); const models = useMemo(() => { const myModelList = myModels.map((item) => ({ @@ -88,9 +96,11 @@ const SlideBar = ({ // init history useEffect(() => { setTimeout(() => { + fetchMyModels(); + fetchCollectionModels(); loadChatHistory(); - }, 1000); - }, [loadChatHistory]); + }, 1500); + }, [fetchCollectionModels, fetchMyModels, loadChatHistory]); /** * export md diff --git a/src/pages/chat/index.tsx b/src/pages/chat/index.tsx index 96937cbd1..cdd7878c7 100644 --- a/src/pages/chat/index.tsx +++ b/src/pages/chat/index.tsx @@ -32,14 +32,13 @@ import dynamic from 'next/dynamic'; import { useGlobalStore } from '@/store/global'; import { useCopyData } from '@/utils/tools'; import { streamFetch } from '@/api/fetch'; -import Icon from '@/components/Icon'; import MyIcon from '@/components/Icon'; import { throttle } from 'lodash'; import { Types } from 'mongoose'; +import Markdown from '@/components/Markdown'; const SlideBar = dynamic(() => import('./components/SlideBar')); const Empty = dynamic(() => import('./components/Empty')); -const Markdown = dynamic(() => import('@/components/Markdown')); import styles from './index.module.scss'; @@ -149,7 +148,7 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => { if (isScroll && res.history.length > 0) { setTimeout(() => { scrollToBottom('auto'); - }, 1200); + }, 1000); } } catch (e: any) { toast({ @@ -428,7 +427,7 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => { px={7} > - { bottom={'15px'} > {isChatting ? ( - { }} /> ) : ( -