perf: chat load

This commit is contained in:
archer
2023-05-02 14:18:43 +08:00
parent 90456301d2
commit 11f42ad9ed
2 changed files with 20 additions and 11 deletions

View File

@@ -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

View File

@@ -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}
>
<Box onClick={onOpenSlider}>
<Icon
<MyIcon
name={'menu'}
w={'20px'}
h={'20px'}
@@ -615,7 +614,7 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
bottom={'15px'}
>
{isChatting ? (
<Icon
<MyIcon
className={styles.stopIcon}
width={['22px', '25px']}
height={['22px', '25px']}
@@ -627,7 +626,7 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
}}
/>
) : (
<Icon
<MyIcon
name={'chatSend'}
width={['18px', '20px']}
height={['18px', '20px']}