mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-21 11:43:56 +00:00
perf: mongo index;fix: loading status and abort chat, system prompt empty
This commit is contained in:
@@ -50,7 +50,7 @@ export const streamFetch = ({ url, data, onMessage, abortSignal }: StreamFetchPr
|
||||
read();
|
||||
} catch (err: any) {
|
||||
if (err?.message === 'The user aborted a request.') {
|
||||
return resolve({ responseText, newChatId, quoteLen, systemPrompt: '' });
|
||||
return resolve({ responseText, newChatId, quoteLen, systemPrompt });
|
||||
}
|
||||
reject(typeof err === 'string' ? err : err?.message || '请求异常');
|
||||
}
|
||||
|
@@ -26,7 +26,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
|
||||
userId
|
||||
});
|
||||
if (authCount >= 30) {
|
||||
throw new Error('上限 30 个助手');
|
||||
throw new Error('上限 30 个应用');
|
||||
}
|
||||
|
||||
// 创建模型
|
||||
|
@@ -1,6 +1,6 @@
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { jsonRes } from '@/service/response';
|
||||
import { connectToDatabase, Collection, Model } from '@/service/mongo';
|
||||
import { connectToDatabase, Model } from '@/service/mongo';
|
||||
import type { PagingData } from '@/types';
|
||||
import type { ShareModelItem } from '@/types/model';
|
||||
import { parseCookie } from '@/service/utils/auth';
|
||||
|
@@ -16,18 +16,18 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
|
||||
await connectToDatabase();
|
||||
|
||||
// 根据 id 获取用户账单
|
||||
const bills = await Bill.find({
|
||||
const where = {
|
||||
userId
|
||||
})
|
||||
.sort({ _id: -1 }) // 按照创建时间倒序排列
|
||||
.skip((pageNum - 1) * pageSize)
|
||||
.limit(pageSize);
|
||||
};
|
||||
|
||||
// 获取total
|
||||
const total = await Bill.countDocuments({
|
||||
userId
|
||||
});
|
||||
// get bill record and total by record
|
||||
const [bills, total] = await Promise.all([
|
||||
Bill.find(where)
|
||||
.sort({ time: -1 }) // 按照创建时间倒序排列
|
||||
.skip((pageNum - 1) * pageSize)
|
||||
.limit(pageSize),
|
||||
Bill.countDocuments(where)
|
||||
]);
|
||||
|
||||
jsonRes(res, {
|
||||
data: {
|
||||
|
@@ -24,7 +24,7 @@ const KbList = ({ kbId }: { kbId: string }) => {
|
||||
);
|
||||
|
||||
/* 加载模型 */
|
||||
const { isLoading } = useQuery(['loadModels'], () => loadKbList(false));
|
||||
const { isFetching } = useQuery(['loadModels'], () => loadKbList(false));
|
||||
|
||||
const handleCreateModel = useCallback(async () => {
|
||||
setIsLoading(true);
|
||||
@@ -133,7 +133,7 @@ const KbList = ({ kbId }: { kbId: string }) => {
|
||||
</Flex>
|
||||
))}
|
||||
|
||||
{!isLoading && myKbList.length === 0 && (
|
||||
{!isFetching && myKbList.length === 0 && (
|
||||
<Flex h={'100%'} flexDirection={'column'} alignItems={'center'} pt={'30vh'}>
|
||||
<MyIcon name="empty" w={'48px'} h={'48px'} color={'transparent'} />
|
||||
<Box mt={2} color={'myGray.500'}>
|
||||
@@ -142,7 +142,7 @@ const KbList = ({ kbId }: { kbId: string }) => {
|
||||
</Flex>
|
||||
)}
|
||||
</Box>
|
||||
<Loading loading={isLoading} fixed={false} />
|
||||
<Loading loading={isFetching} fixed={false} />
|
||||
</Flex>
|
||||
);
|
||||
};
|
||||
|
@@ -19,7 +19,7 @@ const ModelList = ({ modelId }: { modelId: string }) => {
|
||||
const [searchText, setSearchText] = useState('');
|
||||
|
||||
/* 加载模型 */
|
||||
const { isLoading } = useQuery(['loadModels'], () => loadMyModels(false));
|
||||
const { isFetching } = useQuery(['loadModels'], () => loadMyModels(false));
|
||||
|
||||
const onclickCreateModel = useCallback(async () => {
|
||||
setIsLoading(true);
|
||||
@@ -77,7 +77,7 @@ const ModelList = ({ modelId }: { modelId: string }) => {
|
||||
<Flex flex={1} mr={2} position={'relative'} alignItems={'center'}>
|
||||
<Input
|
||||
h={'32px'}
|
||||
placeholder="搜索 AI 助手"
|
||||
placeholder="搜索 AI 应用"
|
||||
value={searchText}
|
||||
onChange={(e) => setSearchText(e.target.value)}
|
||||
/>
|
||||
@@ -149,16 +149,16 @@ const ModelList = ({ modelId }: { modelId: string }) => {
|
||||
</Box>
|
||||
))}
|
||||
|
||||
{!isLoading && totalModels === 0 && (
|
||||
{!isFetching && totalModels === 0 && (
|
||||
<Flex h={'100%'} flexDirection={'column'} alignItems={'center'} pt={'30vh'}>
|
||||
<MyIcon name="empty" w={'48px'} h={'48px'} color={'transparent'} />
|
||||
<Box mt={2} color={'myGray.500'}>
|
||||
还没有 AI 助手~
|
||||
还没有 AI 应用~
|
||||
</Box>
|
||||
</Flex>
|
||||
)}
|
||||
</Box>
|
||||
<Loading loading={isLoading} fixed={false} />
|
||||
<Loading loading={isFetching} fixed={false} />
|
||||
</Flex>
|
||||
);
|
||||
};
|
||||
|
@@ -43,4 +43,11 @@ const BillSchema = new Schema({
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
BillSchema.index({ time: -1 });
|
||||
BillSchema.index({ userId: 1 });
|
||||
} catch (error) {
|
||||
error;
|
||||
}
|
||||
|
||||
export const Bill: Model<BillType> = models['bill'] || model('bill', BillSchema);
|
||||
|
@@ -82,4 +82,11 @@ const ModelSchema = new Schema({
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
ModelSchema.index({ updateTime: -1 });
|
||||
ModelSchema.index({ 'share.collection': -1 });
|
||||
} catch (error) {
|
||||
error;
|
||||
}
|
||||
|
||||
export const Model: MongoModel<ModelType> = models['model'] || model('model', ModelSchema);
|
||||
|
Reference in New Issue
Block a user