diff --git a/wee/webscraper/src/performance.interceptor.ts b/wee/webscraper/src/performance.interceptor.ts new file mode 100644 index 000000000..56a27ca1e --- /dev/null +++ b/wee/webscraper/src/performance.interceptor.ts @@ -0,0 +1,27 @@ +import { + CallHandler, + ExecutionContext, + Injectable, + NestInterceptor, +} from '@nestjs/common'; +import { Observable } from 'rxjs'; +import { tap } from 'rxjs/operators'; +import { performance } from 'perf_hooks'; + +@Injectable() +export class PerformanceInterceptor implements NestInterceptor { + intercept(context: ExecutionContext, next: CallHandler): Observable { + const now = performance.now(); + return next + .handle() + .pipe( + tap(() => + console.log( + `${context.getClass().name} - ${context.getHandler().name} executed in ${( + performance.now() - now + ).toFixed(2)}ms`, + ), + ), + ); + } +} diff --git a/wee/webscraper/src/scraper.controller.ts b/wee/webscraper/src/scraper.controller.ts index 7e8247165..2c5318d86 100644 --- a/wee/webscraper/src/scraper.controller.ts +++ b/wee/webscraper/src/scraper.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Get, Query } from '@nestjs/common'; +import { Controller, Get, Query, UseInterceptors , } from '@nestjs/common'; import { ScraperService } from './scraper.service'; import { ApiTags } from '@nestjs/swagger'; import { Metadata } from './models/ServiceModels'; @@ -14,13 +14,15 @@ import { ScrapeContactInfoOperation, ScrapeContactInfoQuery, ScrapeContactInfoResponse200, ScrapeContactInfoResponse400, ScrapeContactInfoResponse500, ScrapeAddressesOperation, ScrapeAddressesQuery, ScrapeAddressesResponse200, ScrapeAddressesResponse400, ScrapeAddressesResponse500, SeoAnalysisOperation, SeoAnalysisQuery, SeoAnalysisResponse200, SeoAnalysisResponse400, SeoAnalysisResponse500, - + } from './scraper.api'; +import { PerformanceInterceptor } from './performance.interceptor'; import { StringDecoder } from 'string_decoder'; @ApiTags('Scraping') @Controller('scraper') +@UseInterceptors(PerformanceInterceptor) export class ScraperController { constructor( private readonly scraperService: ScraperService,