From ac9e280754aebffb268ad1e85e261962169b6fa6 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Wed, 19 Jun 2024 15:29:30 -0500 Subject: [PATCH 1/2] fix: remove xml cache for IDE team --- .../convertContext/recompositionFinalizer.ts | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/convert/convertContext/recompositionFinalizer.ts b/src/convert/convertContext/recompositionFinalizer.ts index 3b256e16c7..2a6a930867 100644 --- a/src/convert/convertContext/recompositionFinalizer.ts +++ b/src/convert/convertContext/recompositionFinalizer.ts @@ -20,8 +20,6 @@ import { ConvertTransactionFinalizer } from './transactionFinalizer'; Messages.importMessagesDirectory(__dirname); const messages = Messages.loadMessages('@salesforce/source-deploy-retrieve', 'sdr'); -const xmlCache = new Map(); - type RecompositionStateValue = { /** * Parent component that children are rolled up into @@ -73,13 +71,13 @@ type ChildWithXml = { }; const recompose = async (stateValue: RecompositionStateValueWithParent): Promise => { - await getXmlFromCache(stateValue.component); + await getXml(stateValue.component); const childXmls = await Promise.all( (stateValue.children?.toArray() ?? []).filter(ensureMetadataComponentWithParent).map( async (child): Promise => ({ cmp: child, - xmlContents: await getXmlFromCache(child), + xmlContents: await getXml(child), groupName: getXmlElement(child.type), }) ) @@ -101,7 +99,7 @@ const recompose = async (stateValue: RecompositionStateValueWithParent): Promise const getStartingXml = async (parent: SourceComponent): Promise => parent.type.strategies?.recomposition === RecompositionStrategy.StartEmpty ? {} - : unwrapAndOmitNS(parent.type.name)(await getXmlFromCache(parent)) ?? {}; + : unwrapAndOmitNS(parent.type.name)(await getXml(parent)) ?? {}; /** throw if the parent component isn't in the state entry */ const ensureStateValueWithParent = ( @@ -151,18 +149,12 @@ const toSortedGroups = (items: ChildWithXml[]): JsonMap => { ); }; -/** wrapper around the xml cache. Handles the nonDecomposed "parse from parent" optimization */ -const getXmlFromCache = async (cmp: SourceComponent): Promise => { +/** Handles the nonDecomposed "parse from parent" optimization */ +const getXml = async (cmp: SourceComponent): Promise => { if (!cmp.xml) return {}; - const key = `${cmp.xml}:${cmp.fullName}`; - if (!xmlCache.has(key)) { - const parsed = - cmp.parent?.type.strategies?.transformer === 'nonDecomposed' - ? cmp.parseFromParentXml({ [cmp.parent.type.name]: await getXmlFromCache(cmp.parent) }) - : unwrapAndOmitNS(cmp.type.name)(await cmp.parseXml()) ?? {}; - xmlCache.set(key, parsed); - } - return xmlCache.get(key) ?? {}; + return cmp.parent?.type.strategies?.transformer === 'nonDecomposed' + ? cmp.parseFromParentXml({ [cmp.parent.type.name]: await getXml(cmp.parent) }) + : unwrapAndOmitNS(cmp.type.name)(await cmp.parseXml()) ?? {}; }; /** composed function, exported from module for test */ From 599d6a67012eda4759787c585b9066b07e75ef48 Mon Sep 17 00:00:00 2001 From: mshanemc Date: Wed, 19 Jun 2024 15:46:08 -0500 Subject: [PATCH 2/2] test: change assertions about file read count --- test/convert/convertContext/recomposition.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/convert/convertContext/recomposition.test.ts b/test/convert/convertContext/recomposition.test.ts index b97712bbaa..664e889ba7 100644 --- a/test/convert/convertContext/recomposition.test.ts +++ b/test/convert/convertContext/recomposition.test.ts @@ -84,7 +84,7 @@ describe('Recomposition', () => { ], }, ]); - expect(readFileSpy.callCount).to.equal(3); + expect(readFileSpy.callCount).to.equal(4); }); it('should still recompose if parent xml is empty', async () => { @@ -151,7 +151,7 @@ describe('Recomposition', () => { }, ]); - expect(readFileSpy.callCount, JSON.stringify(readFileSpy.getCalls(), undefined, 2)).to.equal(1); + expect(readFileSpy.callCount, JSON.stringify(readFileSpy.getCalls(), undefined, 2)).to.equal(3); }); describe('should only read unique child xml files once for non-decomposed components', () => { @@ -224,7 +224,7 @@ describe('Recomposition', () => { await context.recomposition.finalize(); - expect(readFileSpy.callCount).to.equal(context.recomposition.transactionState.size); + expect(readFileSpy.callCount).to.equal(3); }); }); });