Skip to content

Commit

Permalink
feat: cache fileResponses on deployResult (#573)
Browse files Browse the repository at this point in the history
* feat: cache fileResponses on deployResult

* chore: adding types for SDR

Co-authored-by: Willie Ruemmele <[email protected]>
  • Loading branch information
mshanemc and WillieRuemmele authored Feb 22, 2022
1 parent 6b7ac71 commit b38185b
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 16 deletions.
1 change: 0 additions & 1 deletion METADATA_SUPPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,6 @@ v55 introduces the following new types. Here's their current level of support
|IndustriesAutomotiveSettings|||
|IndustriesMfgServiceSettings|||
|InvLatePymntRiskCalcSettings|||
|LiveChatObjectAccessDefinition||Not supported, but support could be added|
|PaymentsManagementEnabledSettings|||
|RegisteredExternalService||Not supported, but support could be added|
|StreamingAppDataConnector||Not supported, but support could be added|
Expand Down
35 changes: 20 additions & 15 deletions src/client/metadataApiDeploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export class DeployResult implements MetadataTransferResult {
public readonly response: MetadataApiDeployStatus;
public readonly components: ComponentSet;
private readonly diagnosticUtil = new DiagnosticUtil('metadata');
private fileResponses: FileResponse[];
private readonly shouldConvertPaths = sep !== posix.sep;

public constructor(response: MetadataApiDeployStatus, components: ComponentSet) {
Expand All @@ -38,26 +39,30 @@ export class DeployResult implements MetadataTransferResult {
}

public getFileResponses(): FileResponse[] {
// TODO: Log when messages can't be mapped to components
const messages = this.getDeployMessages(this.response);
const fileResponses: FileResponse[] = [];
// this involves FS operations, so only perform once!
if (!this.fileResponses) {
// TODO: Log when messages can't be mapped to components
const messages = this.getDeployMessages(this.response);
const fileResponses: FileResponse[] = [];

for (const deployedComponent of this.components.getSourceComponents()) {
if (deployedComponent.type.children) {
for (const child of deployedComponent.getChildren()) {
const childMessages = messages.get(this.key(child));
if (childMessages) {
fileResponses.push(...this.createResponses(child, childMessages));
for (const deployedComponent of this.components.getSourceComponents()) {
if (deployedComponent.type.children) {
for (const child of deployedComponent.getChildren()) {
const childMessages = messages.get(this.key(child));
if (childMessages) {
fileResponses.push(...this.createResponses(child, childMessages));
}
}
}
const componentMessages = messages.get(this.key(deployedComponent));
if (componentMessages) {
fileResponses.push(...this.createResponses(deployedComponent, componentMessages));
}
}
const componentMessages = messages.get(this.key(deployedComponent));
if (componentMessages) {
fileResponses.push(...this.createResponses(deployedComponent, componentMessages));
}
}

return fileResponses.concat(this.deleteNotFoundToFileResponses(messages));
this.fileResponses = fileResponses.concat(this.deleteNotFoundToFileResponses(messages));
}
return this.fileResponses;
}

private createResponses(component: SourceComponent, messages: DeployMessage[]): FileResponse[] {
Expand Down
26 changes: 26 additions & 0 deletions test/client/metadataApiDeploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,6 +766,32 @@ describe('MetadataApiDeploy', () => {

expect(responses).to.deep.equal(expected);
});

it('should cache fileResponses', () => {
const component = COMPONENT;
const deployedSet = new ComponentSet([component]);
const apiStatus: Partial<MetadataApiDeployStatus> = {
details: {
componentFailures: {
changed: 'false',
created: 'false',
deleted: 'false',
fullName: 'destructiveChanges.xml',
componentType: component.type.name,
problem: `No ${component.type.name} named: ${component.fullName} found`,
problemType: 'Warning',
} as DeployMessage,
},
};
const result = new DeployResult(apiStatus as MetadataApiDeployStatus, deployedSet);
// @ts-ignore testing private property
const spy = env.spy(result, 'getDeployMessages');

result.getFileResponses();
expect(spy.callCount).to.equal(1);
result.getFileResponses();
expect(spy.callCount).to.equal(1);
});
});
});

Expand Down

0 comments on commit b38185b

Please sign in to comment.