Browse Source

Merge pull request #308 from zilliztech/attu-304

using query for count
ryjiang 1 year ago
parent
commit
65679ef8db

+ 1 - 1
client/src/http/Axios.ts

@@ -12,7 +12,7 @@ export const url =
 
 
 const axiosInstance = axios.create({
 const axiosInstance = axios.create({
   baseURL: `${url}/api/v1`,
   baseURL: `${url}/api/v1`,
-  timeout: 60000,
+  timeout: 60000 * 5, // 5 minutes
 });
 });
 
 
 axiosInstance.interceptors.request.use(
 axiosInstance.interceptors.request.use(

+ 3 - 3
client/src/http/Collection.ts

@@ -173,7 +173,7 @@ export class CollectionHttp extends BaseModel implements CollectionView {
   }
   }
 
 
   get _aliases() {
   get _aliases() {
-    return this.aliases;
+    return this.aliases || [];
   }
   }
 
 
   get _desc() {
   get _desc() {
@@ -234,11 +234,11 @@ export class CollectionHttp extends BaseModel implements CollectionView {
   }
   }
 
 
   get _replicas(): Replica[] {
   get _replicas(): Replica[] {
-    return this.replicas;
+    return this.replicas || [];
   }
   }
 
 
   get _enableDynamicField(): boolean {
   get _enableDynamicField(): boolean {
-    return this.schema.enable_dynamic_field;
+    return this.schema && this.schema.enable_dynamic_field;
   }
   }
 
 
   get _schema() {
   get _schema() {

+ 1 - 0
client/src/i18n/en/collection.ts

@@ -3,6 +3,7 @@ const collectionTrans = {
   noData: 'No Collection',
   noData: 'No Collection',
 
 
   rowCount: 'Approx Count',
   rowCount: 'Approx Count',
+  count: 'Entity Count',
 
 
   create: 'Collection',
   create: 'Collection',
   delete: 'delete',
   delete: 'delete',

+ 1 - 1
client/src/i18n/en/dialog.ts

@@ -9,7 +9,7 @@ const dialogTrans = {
   loadTitle: `Load {{type}}`,
   loadTitle: `Load {{type}}`,
 
 
   loadContent: `You are trying to load a {{type}} with data. Only loaded {{type}} can be searched.`,
   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}}"`,
   createTitle: `Create {{type}} on "{{name}}"`,
 };
 };

+ 1 - 1
client/src/i18n/en/overview.ts

@@ -1,7 +1,7 @@
 const overviewTrans = {
 const overviewTrans = {
   load: 'Loaded Collections',
   load: 'Loaded Collections',
   all: 'All Collections',
   all: 'All Collections',
-  data: 'Entities',
+  data: 'Approx Entities',
   rows: '{{number}}',
   rows: '{{number}}',
   loading: 'Loading Collections',
   loading: 'Loading Collections',
   sysInfo: 'System Info',
   sysInfo: 'System Info',

+ 11 - 6
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 { WS_EVENTS, WS_EVENTS_TYPE } from '@server/utils/Const';
 import { useNavigationHook } from '@/hooks';
 import { useNavigationHook } from '@/hooks';
 import { CollectionHttp, MilvusHttp } from '@/http';
 import { CollectionHttp, MilvusHttp } from '@/http';
+import { ShowCollectionsType } from '@/types/Milvus';
 import { ALL_ROUTER_TYPES } from '@/router/Types';
 import { ALL_ROUTER_TYPES } from '@/router/Types';
 import { checkLoading, checkIndexBuilding, formatNumber } from '@/utils';
 import { checkLoading, checkIndexBuilding, formatNumber } from '@/utils';
 import CollectionCard from './collectionCard/CollectionCard';
 import CollectionCard from './collectionCard/CollectionCard';
@@ -106,6 +107,11 @@ const SysCard = (data: {
   );
   );
 };
 };
 
 
+type statisticsType = {
+  collectionCount: number;
+  totalData: number;
+};
+
 const Overview = () => {
 const Overview = () => {
   useNavigationHook(ALL_ROUTER_TYPES.OVERVIEW);
   useNavigationHook(ALL_ROUTER_TYPES.OVERVIEW);
   const { database, databases, data } = useContext(dataContext);
   const { database, databases, data } = useContext(dataContext);
@@ -114,10 +120,7 @@ const Overview = () => {
   const { t: overviewTrans } = useTranslation('overview');
   const { t: overviewTrans } = useTranslation('overview');
   const { t: collectionTrans } = useTranslation('collection');
   const { t: collectionTrans } = useTranslation('collection');
   const { t: successTrans } = useTranslation('success');
   const { t: successTrans } = useTranslation('success');
-  const [statistics, setStatistics] = useState<{
-    collectionCount: number;
-    totalData: number;
-  }>({
+  const [statistics, setStatistics] = useState<statisticsType>({
     collectionCount: 0,
     collectionCount: 0,
     totalData: 0,
     totalData: 0,
   });
   });
@@ -127,8 +130,10 @@ const Overview = () => {
 
 
   const fetchData = useCallback(async () => {
   const fetchData = useCallback(async () => {
     setLoading(true);
     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(
     const hasLoadingOrBuildingCollection = collections.some(
       v => checkLoading(v) || checkIndexBuilding(v)
       v => checkLoading(v) || checkIndexBuilding(v)
     );
     );

+ 1 - 1
client/src/pages/overview/collectionCard/CollectionCard.tsx

@@ -146,7 +146,7 @@ const CollectionCard: FC<CollectionCardProps> = ({
             </li>
             </li>
           ) : null}
           ) : null}
           <li>
           <li>
-            <Typography>{collectionTrans('rowCount')}</Typography>:
+            <Typography>{collectionTrans('count')}</Typography>:
             <Typography className={classes.rowCount}>{rowCount}</Typography>
             <Typography className={classes.rowCount}>{rowCount}</Typography>
           </li>
           </li>
         </ul>
         </ul>

+ 24 - 4
server/src/collections/collections.service.ts

@@ -20,6 +20,7 @@ import {
   GetQuerySegmentInfoReq,
   GetQuerySegmentInfoReq,
   GePersistentSegmentInfoReq,
   GePersistentSegmentInfoReq,
   CompactReq,
   CompactReq,
+  CountReq,
 } from '@zilliz/milvus2-sdk-node';
 } from '@zilliz/milvus2-sdk-node';
 import { throwErrorFromSDK, findKeyValue, genRows, ROW_COUNT } from '../utils';
 import { throwErrorFromSDK, findKeyValue, genRows, ROW_COUNT } from '../utils';
 import { QueryDto, ImportSampleDto, GetReplicasDto } from './dto';
 import { QueryDto, ImportSampleDto, GetReplicasDto } from './dto';
@@ -75,6 +76,12 @@ export class CollectionsService {
     return res;
     return res;
   }
   }
 
 
+  async count(data: CountReq) {
+    const res = await this.milvusService.client.count(data);
+    throwErrorFromSDK(res.status);
+    return res;
+  }
+
   async insert(data: InsertReq) {
   async insert(data: InsertReq) {
     const res = await this.milvusService.client.insert(data);
     const res = await this.milvusService.client.insert(data);
     throwErrorFromSDK(res.status);
     throwErrorFromSDK(res.status);
@@ -223,13 +230,26 @@ export class CollectionsService {
     if (res.data.length > 0) {
     if (res.data.length > 0) {
       for (const item of res.data) {
       for (const item of res.data) {
         const { id, name } = item;
         const { id, name } = item;
-        const collectionStatistics = await this.getCollectionStatistics({
-          collection_name: name,
-        });
+
+        let count: number | string;
+
+        try {
+          const countRes = await this.count({
+            collection_name: name,
+          });
+          count = countRes.data;
+        } catch (error) {
+          const collectionStatisticsRes = await this.getCollectionStatistics({
+            collection_name: name,
+          });
+          count = collectionStatisticsRes.data.row_count;
+        }
+
         data.push({
         data.push({
           id,
           id,
           collection_name: name,
           collection_name: name,
-          rowCount: findKeyValue(collectionStatistics.stats, ROW_COUNT),
+          rowCount: count,
+          ...item,
         });
         });
       }
       }
     }
     }