Sfoglia il codice sorgente

fix 12s waiting for the query request (#687)

Signed-off-by: ryjiang <jiangruiyi@gmail.com>
ryjiang 10 mesi fa
parent
commit
e1051a48b1
1 ha cambiato i file con 16 aggiunte e 9 eliminazioni
  1. 16 9
      server/src/collections/collections.service.ts

+ 16 - 9
server/src/collections/collections.service.ts

@@ -28,6 +28,7 @@ import {
   DataType,
   HybridSearchReq,
   SearchSimpleReq,
+  LoadState,
 } from '@zilliz/milvus2-sdk-node';
 import { Parser } from '@json2csv/plainjs';
 import {
@@ -246,15 +247,21 @@ export class CollectionsService {
     const { milvusClient } = clientCache.get(clientId);
     let count = 0;
     try {
-      const countRes = await milvusClient.count(data);
-      count = countRes.data;
-    } catch (error) {
-      const collectionStatisticsRes = await this.getCollectionStatistics(
-        clientId,
-        data
-      );
-      count = collectionStatisticsRes.data.row_count;
-    }
+      // check if the collection is loaded
+      const loadStateRes = await milvusClient.getLoadState(data);
+
+      if (loadStateRes.state === LoadState.LoadStateLoaded) {
+        const countRes = await milvusClient.count(data);
+        count = countRes.data;
+      } else {
+        const collectionStatisticsRes = await this.getCollectionStatistics(
+          clientId,
+          data
+        );
+        count = collectionStatisticsRes.data.row_count;
+      }
+    } catch (error) {}
+
     return { rowCount: Number(count) } as CountObject;
   }