Browse Source

Avoid requesting another db while loading the current db (#567)

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

+ 4 - 1
client/src/pages/home/Home.tsx

@@ -78,11 +78,14 @@ const Home = () => {
     return `${duration.toFixed(2)} ${unit}`;
   }, [data.rootCoord]);
 
+  // make sure the database has collections data
+  const isLoading = loadingDatabases || collections.every(c => !c.schema);
+
   return (
     <section className={`page-wrapper  ${classes.overviewContainer}`}>
       <section className={classes.section}>
         <Typography variant="h4">{databaseTrans('databases')}</Typography>
-        {loadingDatabases ? (
+        {isLoading ? (
           <StatusIcon type={LoadingType.CREATING} />
         ) : (
           <div className={classes.cardWrapper}>

+ 15 - 13
server/src/collections/collections.service.ts

@@ -6,7 +6,6 @@ import {
   InsertReq,
   LoadCollectionReq,
   ReleaseLoadCollectionReq,
-  SearchReq,
   RenameCollectionReq,
   AlterAliasReq,
   CreateAliasReq,
@@ -261,7 +260,7 @@ export class CollectionsService {
     const searchParams = data as HybridSearchReq;
     const isHybrid =
       Array.isArray(searchParams.data) && searchParams.data.length > 1;
-    let singleSearchParams = cloneObj(data) as SearchSimpleReq;
+    const singleSearchParams = cloneObj(data) as SearchSimpleReq;
 
     // for 2.3.x milvus
     if (searchParams.data && searchParams.data.length === 1) {
@@ -441,12 +440,12 @@ export class CollectionsService {
     clientId: string,
     collections: string[] = []
   ): Promise<CollectionObject[]> {
-    const cache = clientCache.get(clientId);
+    const currentClient = clientCache.get(clientId);
 
     // clear collectionsQueue if we fetch all collections
     if (collections.length === 0) {
-      cache.collectionsQueue.stop();
-      cache.collectionsQueue = new SimpleQueue<string>();
+      currentClient.collectionsQueue.stop();
+      currentClient.collectionsQueue = new SimpleQueue<string>();
     }
 
     // get all collections(name, timestamp, id)
@@ -490,14 +489,17 @@ export class CollectionsService {
     }
 
     // start the queue
-    if (cache.collectionsQueue.size() > 0) {
-      cache.collectionsQueue.executeNext(async (collectionsToGet, q) => {
-        // if the queue is obseleted, return
-        if (q.isObseleted) {
-          return;
-        }
-        await this.updateCollectionsDetails(clientId, collectionsToGet);
-      }, 5);
+    if (currentClient.collectionsQueue.size() > 0) {
+      currentClient.collectionsQueue.executeNext(
+        async (collectionsToGet, q) => {
+          // if the queue is obseleted, return
+          if (q.isObseleted) {
+            return;
+          }
+          await this.updateCollectionsDetails(clientId, collectionsToGet);
+        },
+        5
+      );
     }
 
     // return data

+ 7 - 2
server/src/database/databases.service.ts

@@ -6,6 +6,7 @@ import {
 import { throwErrorFromSDK } from '../utils/Error';
 import { clientCache } from '../app';
 import { DatabaseObject } from '../types';
+import { SimpleQueue } from '../utils';
 
 export class DatabasesService {
   async createDatabase(clientId: string, data: CreateDatabaseRequest) {
@@ -59,9 +60,13 @@ export class DatabasesService {
   }
 
   async use(clientId: string, db_name: string) {
-    const { milvusClient } = clientCache.get(clientId);
+    const currentClient = clientCache.get(clientId);
+
+    // clear collectionsQueue when switching database
+    currentClient.collectionsQueue.stop();
+    currentClient.collectionsQueue = new SimpleQueue<string>();
 
-    return await await milvusClient.use({ db_name });
+    return await await currentClient.milvusClient.use({ db_name });
   }
 
   async hasDatabase(clientId: string, data: string) {