|
@ -8,8 +8,6 @@ import { |
|
|
import { Observable } from 'rxjs'; |
|
|
import { Observable } from 'rxjs'; |
|
|
import { tap } from 'rxjs/operators'; |
|
|
import { tap } from 'rxjs/operators'; |
|
|
|
|
|
|
|
|
const dict = {}; |
|
|
|
|
|
|
|
|
|
|
|
@Injectable() |
|
|
@Injectable() |
|
|
export class LoggingInterceptor implements NestInterceptor { |
|
|
export class LoggingInterceptor implements NestInterceptor { |
|
|
intercept(context: ExecutionContext, next: CallHandler): Observable<any> { |
|
|
intercept(context: ExecutionContext, next: CallHandler): Observable<any> { |
|
@ -32,21 +30,12 @@ export function LogPerformance( |
|
|
descriptor: PropertyDescriptor |
|
|
descriptor: PropertyDescriptor |
|
|
) { |
|
|
) { |
|
|
const originalMethod = descriptor.value; |
|
|
const originalMethod = descriptor.value; |
|
|
if (Object.keys(dict).includes(propertyKey)) { |
|
|
|
|
|
dict[propertyKey] += 1; |
|
|
|
|
|
} else { |
|
|
|
|
|
dict[propertyKey] = 1; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
descriptor.value = function (...args: any[]) { |
|
|
descriptor.value = function (...args: any[]) { |
|
|
const time = Date.now(); |
|
|
const time = Date.now(); |
|
|
const result = originalMethod.apply(this, args); |
|
|
const result = originalMethod.apply(this, args); |
|
|
const now = Date.now(); |
|
|
const now = Date.now(); |
|
|
if (now - time > 100) { |
|
|
if (now - time > 100) { |
|
|
Logger.debug(`${propertyKey} returned within: ${now - time} ms`); |
|
|
Logger.debug(`${propertyKey} returned within: ${now - time} ms`); |
|
|
} else if (dict[propertyKey] > 100) { |
|
|
|
|
|
Logger.debug(`${propertyKey} was called the 100th time`); |
|
|
|
|
|
dict[propertyKey] = 0; |
|
|
|
|
|
} |
|
|
} |
|
|
return result; |
|
|
return result; |
|
|
}; |
|
|
}; |
|
|