From ce07f513bc2d17f3ddda1d2274a2727912e34d83 Mon Sep 17 00:00:00 2001 From: ryjiang Date: Tue, 7 Nov 2023 15:13:07 +0800 Subject: [PATCH 1/2] using query for count Signed-off-by: ryjiang --- client/src/http/Axios.ts | 2 +- client/src/http/Collection.ts | 6 ++-- client/src/i18n/en/collection.ts | 1 + client/src/i18n/en/dialog.ts | 2 +- client/src/i18n/en/overview.ts | 2 +- client/src/pages/overview/Overview.tsx | 17 +++++++---- .../collectionCard/CollectionCard.tsx | 2 +- server/src/collections/collections.service.ts | 28 ++++++++++++++++--- 8 files changed, 43 insertions(+), 17 deletions(-) diff --git a/client/src/http/Axios.ts b/client/src/http/Axios.ts index 8af7949c..3edd51fa 100644 --- a/client/src/http/Axios.ts +++ b/client/src/http/Axios.ts @@ -12,7 +12,7 @@ export const url = const axiosInstance = axios.create({ baseURL: `${url}/api/v1`, - timeout: 60000, + timeout: 60000 * 5, // 5 minutes }); axiosInstance.interceptors.request.use( diff --git a/client/src/http/Collection.ts b/client/src/http/Collection.ts index d94dc7b3..0b33c64a 100644 --- a/client/src/http/Collection.ts +++ b/client/src/http/Collection.ts @@ -173,7 +173,7 @@ export class CollectionHttp extends BaseModel implements CollectionView { } get _aliases() { - return this.aliases; + return this.aliases || []; } get _desc() { @@ -234,11 +234,11 @@ export class CollectionHttp extends BaseModel implements CollectionView { } get _replicas(): Replica[] { - return this.replicas; + return this.replicas || []; } get _enableDynamicField(): boolean { - return this.schema.enable_dynamic_field; + return this.schema && this.schema.enable_dynamic_field; } get _schema() { diff --git a/client/src/i18n/en/collection.ts b/client/src/i18n/en/collection.ts index 58156dca..fdab4cfb 100644 --- a/client/src/i18n/en/collection.ts +++ b/client/src/i18n/en/collection.ts @@ -3,6 +3,7 @@ const collectionTrans = { noData: 'No Collection', rowCount: 'Approx Count', + count: 'Entity Count', create: 'Collection', delete: 'delete', diff --git a/client/src/i18n/en/dialog.ts b/client/src/i18n/en/dialog.ts index 02578662..5859a8c1 100644 --- a/client/src/i18n/en/dialog.ts +++ b/client/src/i18n/en/dialog.ts @@ -9,7 +9,7 @@ const dialogTrans = { loadTitle: `Load {{type}}`, loadContent: `You are trying to load a {{type}} with data. Only loaded {{type}} can be searched.`, - releaseContent: `You are trying to release a {{type}} with data. Please be aware that the data will no longer be available for search.`, + releaseContent: `You are trying to release {{type}} with data. Please be aware that the data will no longer be available for search.`, createTitle: `Create {{type}} on "{{name}}"`, }; diff --git a/client/src/i18n/en/overview.ts b/client/src/i18n/en/overview.ts index 1225e633..e32efd3c 100644 --- a/client/src/i18n/en/overview.ts +++ b/client/src/i18n/en/overview.ts @@ -1,7 +1,7 @@ const overviewTrans = { load: 'Loaded Collections', all: 'All Collections', - data: 'Entities', + data: 'Approx Entities', rows: '{{number}}', loading: 'Loading Collections', sysInfo: 'System Info', diff --git a/client/src/pages/overview/Overview.tsx b/client/src/pages/overview/Overview.tsx index 889ce762..aea2dec8 100644 --- a/client/src/pages/overview/Overview.tsx +++ b/client/src/pages/overview/Overview.tsx @@ -17,6 +17,7 @@ import { LOADING_STATE, MILVUS_DEPLOY_MODE } from '@/consts'; import { WS_EVENTS, WS_EVENTS_TYPE } from '@server/utils/Const'; import { useNavigationHook } from '@/hooks'; import { CollectionHttp, MilvusHttp } from '@/http'; +import { ShowCollectionsType } from '@/types/Milvus'; import { ALL_ROUTER_TYPES } from '@/router/Types'; import { checkLoading, checkIndexBuilding, formatNumber } from '@/utils'; import CollectionCard from './collectionCard/CollectionCard'; @@ -106,6 +107,11 @@ const SysCard = (data: { ); }; +type statisticsType = { + collectionCount: number; + totalData: number; +}; + const Overview = () => { useNavigationHook(ALL_ROUTER_TYPES.OVERVIEW); const { database, databases, data } = useContext(dataContext); @@ -114,10 +120,7 @@ const Overview = () => { const { t: overviewTrans } = useTranslation('overview'); const { t: collectionTrans } = useTranslation('collection'); const { t: successTrans } = useTranslation('success'); - const [statistics, setStatistics] = useState<{ - collectionCount: number; - totalData: number; - }>({ + const [statistics, setStatistics] = useState({ collectionCount: 0, totalData: 0, }); @@ -127,8 +130,10 @@ const Overview = () => { const fetchData = useCallback(async () => { setLoading(true); - const res = await CollectionHttp.getStatistics(); - const collections = await CollectionHttp.getCollections(); + const res = (await CollectionHttp.getStatistics()) as statisticsType; + const collections = await CollectionHttp.getCollections({ + type: ShowCollectionsType.InMemory, + }); const hasLoadingOrBuildingCollection = collections.some( v => checkLoading(v) || checkIndexBuilding(v) ); diff --git a/client/src/pages/overview/collectionCard/CollectionCard.tsx b/client/src/pages/overview/collectionCard/CollectionCard.tsx index 202b47c7..1ad96ee4 100644 --- a/client/src/pages/overview/collectionCard/CollectionCard.tsx +++ b/client/src/pages/overview/collectionCard/CollectionCard.tsx @@ -146,7 +146,7 @@ const CollectionCard: FC = ({ ) : null}
  • - {collectionTrans('rowCount')}: + {collectionTrans('count')}: {rowCount}
  • diff --git a/server/src/collections/collections.service.ts b/server/src/collections/collections.service.ts index a394e0f0..03539486 100644 --- a/server/src/collections/collections.service.ts +++ b/server/src/collections/collections.service.ts @@ -20,6 +20,7 @@ import { GetQuerySegmentInfoReq, GePersistentSegmentInfoReq, CompactReq, + CountReq, } from '@zilliz/milvus2-sdk-node'; import { throwErrorFromSDK, findKeyValue, genRows, ROW_COUNT } from '../utils'; import { QueryDto, ImportSampleDto, GetReplicasDto } from './dto'; @@ -75,6 +76,12 @@ export class CollectionsService { return res; } + async count(data: CountReq) { + const res = await this.milvusService.client.count(data); + throwErrorFromSDK(res.status); + return res; + } + async insert(data: InsertReq) { const res = await this.milvusService.client.insert(data); throwErrorFromSDK(res.status); @@ -223,13 +230,26 @@ export class CollectionsService { if (res.data.length > 0) { for (const item of res.data) { const { id, name } = item; - const collectionStatistics = await this.getCollectionStatistics({ - collection_name: name, - }); + + let count: number | string; + + try { + const res = await this.count({ + collection_name: name, + }); + count = res.data; + } catch (error) { + const res = await this.getCollectionStatistics({ + collection_name: name, + }); + count = res.data.row_count; + } + data.push({ id, collection_name: name, - rowCount: findKeyValue(collectionStatistics.stats, ROW_COUNT), + rowCount: count, + ...item, }); } } From 448f495f6bcf90381fdf36804be0d59b2d05955d Mon Sep 17 00:00:00 2001 From: ryjiang Date: Tue, 7 Nov 2023 15:20:35 +0800 Subject: [PATCH 2/2] fix build Signed-off-by: ryjiang --- server/src/collections/collections.service.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/server/src/collections/collections.service.ts b/server/src/collections/collections.service.ts index 03539486..68d8f290 100644 --- a/server/src/collections/collections.service.ts +++ b/server/src/collections/collections.service.ts @@ -234,15 +234,15 @@ export class CollectionsService { let count: number | string; try { - const res = await this.count({ + const countRes = await this.count({ collection_name: name, }); - count = res.data; + count = countRes.data; } catch (error) { - const res = await this.getCollectionStatistics({ + const collectionStatisticsRes = await this.getCollectionStatistics({ collection_name: name, }); - count = res.data.row_count; + count = collectionStatisticsRes.data.row_count; } data.push({