mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 21:13:50 +00:00
perf: chat load
This commit is contained in:
@@ -50,11 +50,19 @@ const SlideBar = ({
|
|||||||
const { isOpen: isOpenWx, onOpen: onOpenWx, onClose: onCloseWx } = useDisclosure();
|
const { isOpen: isOpenWx, onOpen: onOpenWx, onClose: onCloseWx } = useDisclosure();
|
||||||
const preChatId = useRef('chatId'); // 用于校验上一次chatId的情况,判断是否需要刷新历史记录
|
const preChatId = useRef('chatId'); // 用于校验上一次chatId的情况,判断是否需要刷新历史记录
|
||||||
|
|
||||||
const { isSuccess } = useQuery(['getMyModels'], getMyModels, {
|
const { isSuccess, refetch: fetchMyModels } = useQuery(['getMyModels'], getMyModels, {
|
||||||
cacheTime: 5 * 60 * 1000
|
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 models = useMemo(() => {
|
||||||
const myModelList = myModels.map((item) => ({
|
const myModelList = myModels.map((item) => ({
|
||||||
@@ -88,9 +96,11 @@ const SlideBar = ({
|
|||||||
// init history
|
// init history
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
|
fetchMyModels();
|
||||||
|
fetchCollectionModels();
|
||||||
loadChatHistory();
|
loadChatHistory();
|
||||||
}, 1000);
|
}, 1500);
|
||||||
}, [loadChatHistory]);
|
}, [fetchCollectionModels, fetchMyModels, loadChatHistory]);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* export md
|
* export md
|
||||||
|
@@ -32,14 +32,13 @@ import dynamic from 'next/dynamic';
|
|||||||
import { useGlobalStore } from '@/store/global';
|
import { useGlobalStore } from '@/store/global';
|
||||||
import { useCopyData } from '@/utils/tools';
|
import { useCopyData } from '@/utils/tools';
|
||||||
import { streamFetch } from '@/api/fetch';
|
import { streamFetch } from '@/api/fetch';
|
||||||
import Icon from '@/components/Icon';
|
|
||||||
import MyIcon from '@/components/Icon';
|
import MyIcon from '@/components/Icon';
|
||||||
import { throttle } from 'lodash';
|
import { throttle } from 'lodash';
|
||||||
import { Types } from 'mongoose';
|
import { Types } from 'mongoose';
|
||||||
|
import Markdown from '@/components/Markdown';
|
||||||
|
|
||||||
const SlideBar = dynamic(() => import('./components/SlideBar'));
|
const SlideBar = dynamic(() => import('./components/SlideBar'));
|
||||||
const Empty = dynamic(() => import('./components/Empty'));
|
const Empty = dynamic(() => import('./components/Empty'));
|
||||||
const Markdown = dynamic(() => import('@/components/Markdown'));
|
|
||||||
|
|
||||||
import styles from './index.module.scss';
|
import styles from './index.module.scss';
|
||||||
|
|
||||||
@@ -149,7 +148,7 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
|
|||||||
if (isScroll && res.history.length > 0) {
|
if (isScroll && res.history.length > 0) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
scrollToBottom('auto');
|
scrollToBottom('auto');
|
||||||
}, 1200);
|
}, 1000);
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
toast({
|
toast({
|
||||||
@@ -428,7 +427,7 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
|
|||||||
px={7}
|
px={7}
|
||||||
>
|
>
|
||||||
<Box onClick={onOpenSlider}>
|
<Box onClick={onOpenSlider}>
|
||||||
<Icon
|
<MyIcon
|
||||||
name={'menu'}
|
name={'menu'}
|
||||||
w={'20px'}
|
w={'20px'}
|
||||||
h={'20px'}
|
h={'20px'}
|
||||||
@@ -615,7 +614,7 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
|
|||||||
bottom={'15px'}
|
bottom={'15px'}
|
||||||
>
|
>
|
||||||
{isChatting ? (
|
{isChatting ? (
|
||||||
<Icon
|
<MyIcon
|
||||||
className={styles.stopIcon}
|
className={styles.stopIcon}
|
||||||
width={['22px', '25px']}
|
width={['22px', '25px']}
|
||||||
height={['22px', '25px']}
|
height={['22px', '25px']}
|
||||||
@@ -627,7 +626,7 @@ const Chat = ({ modelId, chatId }: { modelId: string; chatId: string }) => {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<Icon
|
<MyIcon
|
||||||
name={'chatSend'}
|
name={'chatSend'}
|
||||||
width={['18px', '20px']}
|
width={['18px', '20px']}
|
||||||
height={['18px', '20px']}
|
height={['18px', '20px']}
|
||||||
|
Reference in New Issue
Block a user