From 2a901219f4af2d548910c8495502907bc852af88 Mon Sep 17 00:00:00 2001 From: kirillgroshkov Date: Wed, 13 Nov 2024 22:59:38 +0100 Subject: [PATCH] feat: CommonDaoCfg.debugValidationTimeThreshhold to debug joi taking >500ms on average on some payloads --- src/commondao/common.dao.model.ts | 13 +++++++++++++ src/commondao/common.dao.ts | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/commondao/common.dao.model.ts b/src/commondao/common.dao.model.ts index 39b73e3..3f708b1 100644 --- a/src/commondao/common.dao.model.ts +++ b/src/commondao/common.dao.model.ts @@ -1,7 +1,9 @@ import { + AnyObject, BaseDBEntity, CommonLogger, ErrorMode, + NumberOfMilliseconds, Promisable, UnixTimestamp, ZodError, @@ -146,6 +148,17 @@ export interface CommonDaoCfg< */ validateOnSave?: boolean + /** + * Defaults to undefined == disabled. + * If set - enable the monitoring of validation time and will alert on crossing the threshold. + */ + debugValidationTimeThreshhold?: NumberOfMilliseconds + + /** + * Called when debugValidationTimeThreshhold is crossed. + */ + onValidationTimeThreshold?: (info: AnyObject) => void + /** * Defaults to false. * Setting it to true will set saveMethod to `insert` for save/saveBatch, which will diff --git a/src/commondao/common.dao.ts b/src/commondao/common.dao.ts index a0a3684..87e49ba 100644 --- a/src/commondao/common.dao.ts +++ b/src/commondao/common.dao.ts @@ -1257,7 +1257,23 @@ export class CommonDao= this.cfg.debugValidationTimeThreshhold + ) { + this.cfg.onValidationTimeThreshold?.({ + tookMillis, + error: !!vr.error, + table, + obj, + }) + } + error = vr.error convertedValue = vr.value }