Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍
TypeScript angularetffinancefintechghostfoliohacktoberfestinvestingnestjsosspersonal-financeportfolioprismasoftwarestocktrackertradingtypescriptwealth-managementweb
Reimplement redactObject() without cloneDeep() (#2760)
Thomas Kaul7c33120546a6
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 3a54642aaa..f7278248a4 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Changed- Set the select column of the lazy-loaded activities table to stick at the end (experimental)+- Improved the performance of the value redaction interceptor for the impersonation mode by eliminating `cloneDeep`## 2.31.0 - 2023-12-16diff --git a/apps/api/src/helper/object.helper.ts b/apps/api/src/helper/object.helper.tsindex 2f0399fb81..1538228b87 100644--- a/apps/api/src/helper/object.helper.ts+++ b/apps/api/src/helper/object.helper.ts@@ -32,9 +32,11 @@ export function nullifyValuesInObjects<T>(aObjects: T[], keys: string[]): T[] {}export function redactAttributes({+ isFirstRun = true,object,options}: {+ isFirstRun?: boolean;object: any;options: { attribute: string; valueMap: { [key: string]: any } }[];}): any {@@ -42,7 +44,10 @@ export function redactAttributes({return object;}- const redactedObject = cloneDeep(object);+ // Create deep clone+ const redactedObject = isFirstRun+ ? JSON.parse(JSON.stringify(object))+ : object;for (const option of options) {if (redactedObject.hasOwnProperty(option.attribute)) {@@ -59,7 +64,11 @@ export function redactAttributes({if (isArray(redactedObject[property])) {redactedObject[property] = redactedObject[property].map((currentObject) => {- return redactAttributes({ options, object: currentObject });+ return redactAttributes({+ options,+ isFirstRun: false,+ object: currentObject+ });});} else if (@@ -69,6 +78,7 @@ export function redactAttributes({// Recursively call the function on the nested objectredactedObject[property] = redactAttributes({options,+ isFirstRun: false,object: redactedObject[property]});}