Browse Source

improve code

Gitea 3 years ago
parent
commit
6e0d7234fe

+ 4 - 5
client/src/context/WebSocket.tsx

@@ -19,7 +19,6 @@ export const WebSocketProvider = (props: { children: React.ReactNode }) => {
 
 
   // test code for socket
   // test code for socket
   useEffect(() => {
   useEffect(() => {
-    console.log('----in websocket-----');
     const socket = io('http://localhost:3000');
     const socket = io('http://localhost:3000');
 
 
     socket.on('connect', function () {
     socket.on('connect', function () {
@@ -37,14 +36,14 @@ export const WebSocketProvider = (props: { children: React.ReactNode }) => {
         (v: any) => new CollectionHttp(v)
         (v: any) => new CollectionHttp(v)
       );
       );
 
 
-      const hasLoadingCollection = collections.find(v => checkLoading(v));
-
-      const hasIndexBuilding = collections.find(v => checkIndexBuilding(v));
+      const hasLoadingOrBuildingCollection = collections.some(
+        v => checkLoading(v) || checkIndexBuilding(v)
+      );
 
 
       setCollections(collections);
       setCollections(collections);
       // If no collection is building index or loading collection
       // If no collection is building index or loading collection
       // stop server cron job
       // stop server cron job
-      if (!hasLoadingCollection && !hasIndexBuilding) {
+      if (!hasLoadingOrBuildingCollection) {
         MilvusHttp.triggerCron({
         MilvusHttp.triggerCron({
           name: WS_EVENTS.COLLECTION,
           name: WS_EVENTS.COLLECTION,
           type: WS_EVENTS_TYPE.STOP,
           type: WS_EVENTS_TYPE.STOP,

+ 5 - 4
client/src/pages/collections/Collections.tsx

@@ -135,10 +135,11 @@ const Collections = () => {
     try {
     try {
       setLoading(true);
       setLoading(true);
       const res = await CollectionHttp.getCollections();
       const res = await CollectionHttp.getCollections();
-      const hasLoadingCollection = res.find(v => checkLoading(v));
-
-      const hasIndexBuilding = res.find(v => checkIndexBuilding(v));
-      if (hasLoadingCollection || hasIndexBuilding) {
+      const hasLoadingOrBuildingCollection = res.some(
+        v => checkLoading(v) || checkIndexBuilding(v)
+      );
+      // if some collection is building index or loading, start pulling data
+      if (hasLoadingOrBuildingCollection) {
         MilvusHttp.triggerCron({
         MilvusHttp.triggerCron({
           name: WS_EVENTS.COLLECTION,
           name: WS_EVENTS.COLLECTION,
           type: WS_EVENTS_TYPE.START,
           type: WS_EVENTS_TYPE.START,