Browse Source

fix error after switching database

Signed-off-by: ryjiang <jiangruiyi@gmail.com>
ryjiang 1 year ago
parent
commit
cbd090a445

+ 27 - 3
client/src/pages/overview/collectionCard/CollectionCard.tsx

@@ -98,7 +98,6 @@ const CollectionCard: FC<CollectionCardProps> = ({
   const navigate = useNavigate();
   // icons
   const RightArrowIcon = icons.rightArrow;
-  const InfoIcon = icons.info;
   const ReleaseIcon = icons.release;
   const VectorSearchIcon = icons.navSearch;
   // i18n
@@ -121,6 +120,7 @@ const CollectionCard: FC<CollectionCardProps> = ({
     navigate({ pathname: '/search', search: `?collectionName=${name}` });
   };
 
+<<<<<<< Updated upstream
   const fetchData = useCallback(async () => {
     try {
       setLoading(true);
@@ -132,9 +132,33 @@ const CollectionCard: FC<CollectionCardProps> = ({
     }
   }, [status]);
 
+=======
+>>>>>>> Stashed changes
   useEffect(() => {
-    fetchData();
-  }, [fetchData, database]);
+    const fetchData = async () => {
+      try {
+        setLoading(true);
+        if (status === LOADING_STATE.LOADED) {
+          const data = (await CollectionHttp.count(name)) as CollectionData;
+          setCount(data._rowCount);
+        }
+      } catch (e) {
+      } finally {
+        setLoading(false);
+      }
+    };
+
+    let exiting = false;
+
+    if (!exiting) {
+      fetchData();
+    }
+
+    return () => {
+      console.log('existing', name, database);
+      exiting = true;
+    };
+  }, [status, database]);
 
   return (
     <Card

+ 7 - 1
server/src/collections/collections.controller.ts

@@ -376,9 +376,15 @@ export class CollectionController {
   async count(req: Request, res: Response, next: NextFunction) {
     const name = req.params?.name;
     try {
-      const result = await this.collectionsService.count({
+      const { value } = await this.collectionsService.hasCollection({
         collection_name: name,
       });
+      let result: any = '';
+      if (value) {
+        result = await this.collectionsService.count({
+          collection_name: name,
+        });
+      }
 
       res.send({ collection_name: name, rowCount: result });
     } catch (error) {

+ 7 - 0
server/src/collections/collections.service.ts

@@ -20,6 +20,7 @@ import {
   GetQuerySegmentInfoReq,
   GePersistentSegmentInfoReq,
   CompactReq,
+  HasCollectionReq,
   CountReq,
 } from '@zilliz/milvus2-sdk-node';
 import { Parser } from '@json2csv/plainjs';
@@ -358,4 +359,10 @@ export class CollectionsService {
     throwErrorFromSDK(res.status);
     return res;
   }
+
+  async hasCollection(data: HasCollectionReq) {
+    const res = await this.milvusService.client.hasCollection(data);
+    throwErrorFromSDK(res.status);
+    return res;
+  }
 }