diff --git a/package-lock.json b/package-lock.json index de6586f..29e0f51 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "@nestjs/core": "^8.0.0", "@nestjs/platform-express": "^8.0.0", "@nestjs/swagger": "^5.0.9", + "cache-manager": "^3.4.4", "class-transformer": "^0.4.0", "class-validator": "^0.13.1", "compression": "^1.7.4", @@ -2733,6 +2734,11 @@ "node": ">=8" } }, + "node_modules/async": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.0.tgz", + "integrity": "sha512-TR2mEZFVOj2pLStYxLht7TyfuRzaydfpxr3k9RpHIzMgw7A64dzsdqCxH1WJyQdoe8T10nDXd9wnEigmiuHIZw==" + }, "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -3113,6 +3119,16 @@ "node": ">= 0.8" } }, + "node_modules/cache-manager": { + "version": "3.4.4", + "resolved": "https://registry.npmjs.org/cache-manager/-/cache-manager-3.4.4.tgz", + "integrity": "sha512-oayy7ukJqNlRUYNUfQBwGOLilL0X5q7GpuaF19Yqwo6qdx49OoTZKRIF5qbbr+Ru8mlTvOpvnMvVq6vw72pOPg==", + "dependencies": { + "async": "3.2.0", + "lodash": "^4.17.21", + "lru-cache": "6.0.0" + } + }, "node_modules/call-bind": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", @@ -6969,7 +6985,6 @@ "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, "dependencies": { "yallist": "^4.0.0" }, @@ -9797,8 +9812,7 @@ "node_modules/yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" }, "node_modules/yaml": { "version": "1.10.2", @@ -11942,6 +11956,11 @@ "integrity": "sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==", "dev": true }, + "async": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/async/-/async-3.2.0.tgz", + "integrity": "sha512-TR2mEZFVOj2pLStYxLht7TyfuRzaydfpxr3k9RpHIzMgw7A64dzsdqCxH1WJyQdoe8T10nDXd9wnEigmiuHIZw==" + }, "asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -12225,6 +12244,16 @@ "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.0.tgz", "integrity": "sha512-zauLjrfCG+xvoyaqLoV8bLVXXNGC4JqlxFCutSDWA6fJrTo2ZuvLYTqZ7aHBLZSMOopbzwv8f+wZcVzfVTI2Dg==" }, + "cache-manager": { + "version": "3.4.4", + "resolved": "https://registry.npmjs.org/cache-manager/-/cache-manager-3.4.4.tgz", + "integrity": "sha512-oayy7ukJqNlRUYNUfQBwGOLilL0X5q7GpuaF19Yqwo6qdx49OoTZKRIF5qbbr+Ru8mlTvOpvnMvVq6vw72pOPg==", + "requires": { + "async": "3.2.0", + "lodash": "^4.17.21", + "lru-cache": "6.0.0" + } + }, "call-bind": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.2.tgz", @@ -15191,7 +15220,6 @@ "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "dev": true, "requires": { "yallist": "^4.0.0" } @@ -17286,8 +17314,7 @@ "yallist": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "dev": true + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" }, "yaml": { "version": "1.10.2", diff --git a/package.json b/package.json index 8917d5b..ae5cb4f 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "@nestjs/core": "^8.0.0", "@nestjs/platform-express": "^8.0.0", "@nestjs/swagger": "^5.0.9", + "cache-manager": "^3.4.4", "class-transformer": "^0.4.0", "class-validator": "^0.13.1", "compression": "^1.7.4", diff --git a/src/modules/contributors/contributors.controller.ts b/src/modules/contributors/contributors.controller.ts index 23d4320..5b29727 100644 --- a/src/modules/contributors/contributors.controller.ts +++ b/src/modules/contributors/contributors.controller.ts @@ -1,5 +1,6 @@ import { TransformInterceptor } from '@common/interceptors'; import { + CacheInterceptor, Controller, Get, Param, @@ -17,14 +18,20 @@ export class ContributorsController { constructor(private readonly contributorService: ContributorsService) {} @Get(':rnc/info/basic') - @UseInterceptors(new TransformInterceptor(ResponseContributorDto)) + @UseInterceptors( + new TransformInterceptor(ResponseContributorDto), + CacheInterceptor, + ) @UseGuards(RncValidatorGuard) getContributors(@Param('rnc') rnc: string) { return this.contributorService.getContributors(rnc); } @Get('search') - @UseInterceptors(new TransformInterceptor(ResponseContributorDto)) + @UseInterceptors( + new TransformInterceptor(ResponseContributorDto), + CacheInterceptor, + ) getContributorByName(@Query('name') name: string) { return this.contributorService.getContributorByName(name); } diff --git a/src/modules/contributors/contributors.module.ts b/src/modules/contributors/contributors.module.ts index 1a9e3b0..9dc0f26 100644 --- a/src/modules/contributors/contributors.module.ts +++ b/src/modules/contributors/contributors.module.ts @@ -1,12 +1,25 @@ -import { Module } from '@nestjs/common'; +import { CacheInterceptor, CacheModule, Module } from '@nestjs/common'; import { ContributorsController } from './contributors.controller'; import { ContributorsService } from './contributors.service'; import { SoapModule } from '@modules/soap/soap.module'; +import { APP_INTERCEPTOR } from '@nestjs/core'; @Module({ - imports: [SoapModule], + imports: [ + SoapModule, + CacheModule.register({ + ttl: 3600, + max: 100, + }), + ], controllers: [ContributorsController], - providers: [ContributorsService], + providers: [ + ContributorsService, + { + provide: APP_INTERCEPTOR, + useClass: CacheInterceptor, + }, + ], }) export class ContributorsModule {} diff --git a/src/modules/contributors/contributors.service.ts b/src/modules/contributors/contributors.service.ts index 580bed4..837820f 100644 --- a/src/modules/contributors/contributors.service.ts +++ b/src/modules/contributors/contributors.service.ts @@ -60,10 +60,10 @@ export class ContributorsService { return new Promise((res, rej) => { const args = { - value: '', //name, + value: name, patronBusqueda: SEARCH_BY_NAME_CODE, - inicioFilas: 1, //SEARCH_FROM, - filaFilas: 10000, //ELEMENTS_PER_PAGE, + inicioFilas: SEARCH_FROM, + filaFilas: ELEMENTS_PER_PAGE, IMEI: '', };