Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove xml cache #1347

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions src/convert/convertContext/recompositionFinalizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import { ConvertTransactionFinalizer } from './transactionFinalizer';
Messages.importMessagesDirectory(__dirname);
const messages = Messages.loadMessages('@salesforce/source-deploy-retrieve', 'sdr');

const xmlCache = new Map<string, JsonMap>();

type RecompositionStateValue = {
/**
* Parent component that children are rolled up into
Expand Down Expand Up @@ -73,13 +71,13 @@ type ChildWithXml = {
};

const recompose = async (stateValue: RecompositionStateValueWithParent): Promise<JsonMap> => {
await getXmlFromCache(stateValue.component);
await getXml(stateValue.component);

const childXmls = await Promise.all(
(stateValue.children?.toArray() ?? []).filter(ensureMetadataComponentWithParent).map(
async (child): Promise<ChildWithXml> => ({
cmp: child,
xmlContents: await getXmlFromCache(child),
xmlContents: await getXml(child),
groupName: getXmlElement(child.type),
})
)
Expand All @@ -101,7 +99,7 @@ const recompose = async (stateValue: RecompositionStateValueWithParent): Promise
const getStartingXml = async (parent: SourceComponent): Promise<JsonMap> =>
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 = (
Expand Down Expand Up @@ -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<JsonMap> => {
/** Handles the nonDecomposed "parse from parent" optimization */
const getXml = async (cmp: SourceComponent): Promise<JsonMap> => {
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 */
Expand Down
6 changes: 3 additions & 3 deletions test/convert/convertContext/recomposition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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);
});
});
});
Expand Down
Loading