Skip to content

Commit

Permalink
perf: usages list;perf: move components (#3654)
Browse files Browse the repository at this point in the history
* perf: usages list

* team sub plan load

* perf: usage dashboard code

* perf: dashboard ui

* perf: move components
  • Loading branch information
c121914yu authored Jan 23, 2025
1 parent 0c05add commit 34b510c
Show file tree
Hide file tree
Showing 271 changed files with 609 additions and 919 deletions.
4 changes: 3 additions & 1 deletion docSite/content/zh-cn/docs/development/upgrading/4820.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ curl --location --request POST 'https://{{host}}/api/admin/initv4820' \

## 完整更新内容

1. 新增 - 可视化模型配置。预设超过 100 个模型,方便进行模型配置。
1. 新增 - 可视化模型配置。预设超过 100 个模型,方便进行模型配置。
2. 新增 - 使用记录导出和仪表盘。
3. 优化 - 页面组件抽离,减少页面组件路由。
10 changes: 10 additions & 0 deletions packages/global/common/error/code/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@ import { ErrType } from '../errorCode';
import { i18nT } from '../../../../web/i18n/utils';
/* team: 503000 */
export enum UserErrEnum {
notUser = 'notUser',
userExist = 'userExist',
unAuthRole = 'unAuthRole',
account_psw_error = 'account_psw_error',
balanceNotEnough = 'balanceNotEnough',
unAuthSso = 'unAuthSso'
}
const errList = [
{
statusText: UserErrEnum.notUser,
message: i18nT('common:code_error.account_not_found')
},
{
statusText: UserErrEnum.userExist,
message: i18nT('common:code_error.account_exist')
},
{
statusText: UserErrEnum.account_psw_error,
message: i18nT('common:code_error.account_error')
Expand Down
17 changes: 8 additions & 9 deletions packages/global/support/wallet/usage/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@ export type CreateTrainingUsageProps = {
datasetId: string;
};

export type GetTotalPointsProps = {
dateStart: Date;
dateEnd: Date;
teamMemberIds: string[];
sources: UsageSourceEnum[];
unit: 'day' | 'week' | 'month';
};

export type GetUsageProps = {
dateStart: Date;
dateEnd: Date;
sources?: UsageSourceEnum[];
teamMemberIds?: string[];
projectName?: string;
isSelectAllTmb?: boolean;
};

export type GetUsageDashboardProps = GetUsageProps & {
unit: 'day' | 'month';
};
export type GetUsageDashboardResponseItem = {
date: Date;
totalPoints: number;
};

export type ConcatUsageProps = UsageListItemCountType & {
Expand Down
2 changes: 1 addition & 1 deletion packages/service/common/middle/reqFrequencyLimit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { jsonRes } from '../response';
// unit: times/s
// how to use?
// export default NextAPI(useQPSLimit(10), handler); // limit 10 times per second for a ip
export function useReqFrequencyLimit(seconds: number, limit: number, force = false) {
export function useIPFrequencyLimit(seconds: number, limit: number, force = false) {
return async (req: ApiRequestProps, res: NextApiResponse) => {
const ip = requestIp.getClientIp(req);
if (!ip || (process.env.USE_IP_LIMIT !== 'true' && !force)) {
Expand Down
115 changes: 1 addition & 114 deletions packages/service/core/dataset/search/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,119 +348,6 @@ export async function searchDatasetData(props: SearchDatasetDataProps) {
};
}

const searchResults = (
await Promise.all(
datasetIds.map(async (id) => {
return MongoDatasetData.aggregate(
[
{
$match: {
teamId: new Types.ObjectId(teamId),
datasetId: new Types.ObjectId(id),
$text: { $search: jiebaSplit({ text: query }) },
...(filterCollectionIdList
? {
collectionId: {
$in: filterCollectionIdList.map((id) => new Types.ObjectId(id))
}
}
: {}),
...(forbidCollectionIdList && forbidCollectionIdList.length > 0
? {
collectionId: {
$nin: forbidCollectionIdList.map((id) => new Types.ObjectId(id))
}
}
: {})
}
},
{
$sort: {
score: { $meta: 'textScore' }
}
},
{
$limit: limit
},
{
$project: {
_id: 1,
datasetId: 1,
collectionId: 1,
updateTime: 1,
q: 1,
a: 1,
chunkIndex: 1,
score: { $meta: 'textScore' }
}
}
],
{
...readFromSecondary
}
);
})
)
).flat() as (DatasetDataSchemaType & { score: number })[];

// Get data and collections
const collections = await MongoDatasetCollection.find(
{
_id: { $in: searchResults.map((item) => item.collectionId) }
},
'_id name fileId rawLink externalFileId externalFileUrl',
{ ...readFromSecondary }
).lean();

return {
fullTextRecallResults: searchResults
.map((data, index) => {
const collection = collections.find(
(col) => String(col._id) === String(data.collectionId)
);
if (!collection) {
console.log('Collection is not found', data);
return;
}

return {
id: String(data._id),
datasetId: String(data.datasetId),
collectionId: String(data.collectionId),
updateTime: data.updateTime,
q: data.q,
a: data.a,
chunkIndex: data.chunkIndex,
indexes: data.indexes,
...getCollectionSourceData(collection),
score: [{ type: SearchScoreTypeEnum.fullText, value: data.score ?? 0, index }]
};
})
.filter(Boolean) as SearchDataResponseItemType[],
tokenLen: 0
};
};
const fullTextRecall2 = async ({
query,
limit,
filterCollectionIdList,
forbidCollectionIdList
}: {
query: string;
limit: number;
filterCollectionIdList?: string[];
forbidCollectionIdList: string[];
}): Promise<{
fullTextRecallResults: SearchDataResponseItemType[];
tokenLen: number;
}> => {
if (limit === 0) {
return {
fullTextRecallResults: [],
tokenLen: 0
};
}

const searchResults = (
await Promise.all(
datasetIds.map(async (id) => {
Expand Down Expand Up @@ -637,7 +524,7 @@ export async function searchDatasetData(props: SearchDatasetDataProps) {
filterCollectionIdList
}),
// FullText tmp
fullTextRecall2({
fullTextRecall({
query,
limit: fullTextLimit,
filterCollectionIdList,
Expand Down
3 changes: 2 additions & 1 deletion packages/service/support/wallet/usage/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ const UsageSchema = new Schema({
});

try {
UsageSchema.index({ teamId: 1, tmbId: 1, source: 1, time: -1 });
UsageSchema.index({ teamId: 1, time: 1, tmbId: 1, source: 1 });
UsageSchema.index({ teamId: 1, time: 1, appName: 1 });
// timer task. clear dead team
// UsageSchema.index({ teamId: 1, time: -1 });

Expand Down
4 changes: 2 additions & 2 deletions packages/web/components/common/DateRangePicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const DateRangePicker = ({
date.to = date.from;
}
setRange(date);
onChange && onChange(date);
onChange?.(date);
}}
footer={
<Flex justifyContent={'flex-end'}>
Expand All @@ -116,7 +116,7 @@ const DateRangePicker = ({
<Button
size={'sm'}
onClick={() => {
onSuccess && onSuccess(range || defaultDate);
onSuccess?.(range || defaultDate);
setShowSelected(false);
}}
>
Expand Down
Loading

0 comments on commit 34b510c

Please sign in to comment.