Browse Source

Merge pull request #199 from nameczz/main

Hide cache for now
ryjiang 3 years ago
parent
commit
bccad009f8
1 changed files with 34 additions and 33 deletions
  1. 34 33
      server/src/collections/collections.controller.ts

+ 34 - 33
server/src/collections/collections.controller.ts

@@ -9,12 +9,12 @@ import {
   Query,
   UsePipes,
   ValidationPipe,
-  CACHE_MANAGER,
-  Inject,
+  // CACHE_MANAGER,
+  // Inject,
   UseInterceptors,
   CacheInterceptor,
 } from '@nestjs/common';
-import { Cache } from 'cache-manager';
+// import { Cache } from 'cache-manager';
 import { ApiTags } from '@nestjs/swagger';
 import { CollectionsService } from './collections.service';
 import {
@@ -23,41 +23,43 @@ import {
   ShowCollections,
   VectorSearch,
 } from './dto';
-import { cacheKeys } from '../cache/config';
+// import { cacheKeys } from '../cache/config';
 
 //Including 2 kind of cache contorl, check getCollections and getStatistics for detail
 @ApiTags('collections')
 @Controller('collections')
 export class CollectionsController {
   constructor(
-    private collectionsService: CollectionsService,
-    @Inject(CACHE_MANAGER) private cacheManager: Cache,
+    private collectionsService: CollectionsService, // @Inject(CACHE_MANAGER) private cacheManager: Cache,
   ) {}
 
   // manually control cache if logic is complicated
   @Get()
   async getCollections(@Query() data?: ShowCollections) {
-    if (Number(data.type) === 1) {
-      let loadedCollections = await this.cacheManager.get(
-        cacheKeys.LOADEDCOLLECTIONS,
-      );
-      if (loadedCollections) {
-        return loadedCollections;
-      }
-      loadedCollections = await this.collectionsService.getLoadedColletions();
-      await this.cacheManager.set(
-        cacheKeys.LOADEDCOLLECTIONS,
-        loadedCollections,
-      );
-      return loadedCollections;
-    }
-    let allCollections = await this.cacheManager.get(cacheKeys.ALLCOLLECTIONS);
-    if (allCollections) {
-      return allCollections;
-    }
-    allCollections = await this.collectionsService.getAllCollections();
-    await this.cacheManager.set(cacheKeys.ALLCOLLECTIONS, allCollections);
-    return allCollections;
+    // if (Number(data.type) === 1) {
+    //   let loadedCollections = await this.cacheManager.get(
+    //     cacheKeys.LOADEDCOLLECTIONS,
+    //   );
+    //   if (loadedCollections) {
+    //     return loadedCollections;
+    //   }
+    //   loadedCollections = await this.collectionsService.getLoadedColletions();
+    //   await this.cacheManager.set(
+    //     cacheKeys.LOADEDCOLLECTIONS,
+    //     loadedCollections,
+    //   );
+    //   return loadedCollections;
+    // }
+    // let allCollections = await this.cacheManager.get(cacheKeys.ALLCOLLECTIONS);
+    // if (allCollections) {
+    //   return allCollections;
+    // }
+    // allCollections = await this.collectionsService.getAllCollections();
+    // await this.cacheManager.set(cacheKeys.ALLCOLLECTIONS, allCollections);
+    // return allCollections;
+    return Number(data.type === 1)
+      ? await this.collectionsService.getLoadedColletions()
+      : await this.collectionsService.getAllCollections();
   }
 
   // use interceptor to control cache automatically
@@ -70,14 +72,13 @@ export class CollectionsController {
   @Post()
   @UsePipes(new ValidationPipe())
   async createCollection(@Body() data: CreateCollection) {
-    await this.cacheManager.del(cacheKeys.ALLCOLLECTIONS);
+    // await this.cacheManager.del(cacheKeys.ALLCOLLECTIONS);
     return await this.collectionsService.createCollection(data);
   }
 
   @Delete(':name')
-  // todo: need check some special symbols
   async deleteCollection(@Param('name') name: string) {
-    await this.cacheManager.del(cacheKeys.ALLCOLLECTIONS);
+    // await this.cacheManager.del(cacheKeys.ALLCOLLECTIONS);
     return await this.collectionsService.dropCollection({
       collection_name: name,
     });
@@ -104,7 +105,7 @@ export class CollectionsController {
 
   @Put(':name/load')
   async loadCollection(@Param('name') name: string) {
-    await this.cacheManager.del(cacheKeys.LOADEDCOLLECTIONS);
+    // await this.cacheManager.del(cacheKeys.LOADEDCOLLECTIONS);
     return await this.collectionsService.loadCollection({
       collection_name: name,
     });
@@ -112,7 +113,7 @@ export class CollectionsController {
 
   @Put(':name/release')
   async releaseCollection(@Param('name') name: string) {
-    await this.cacheManager.del(cacheKeys.LOADEDCOLLECTIONS);
+    // await this.cacheManager.del(cacheKeys.LOADEDCOLLECTIONS);
     return await this.collectionsService.releaseCollection({
       collection_name: name,
     });
@@ -120,7 +121,7 @@ export class CollectionsController {
 
   @Post(':name/insert')
   async insertData(@Param('name') name: string, @Body() data: InsertData) {
-    await this.cacheManager.del(cacheKeys.ALLCOLLECTIONS);
+    // await this.cacheManager.del(cacheKeys.ALLCOLLECTIONS);
     return await this.collectionsService.insert({
       collection_name: name,
       ...data,