Skip to content

Commit

Permalink
fix: address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shetzel committed Dec 5, 2023
1 parent e2618bf commit 4d94595
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
28 changes: 15 additions & 13 deletions src/collections/componentSetBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ export class ComponentSetBuilder {
const logger = Logger.childFromRoot('componentSetBuilder');
let componentSet: ComponentSet | undefined;

// A map used when building a ComponentSet from metadata type/name pairs
// key = a metadata type
// value = an array of metadata names
/**
* A map used when building a ComponentSet from metadata type/name pairs
* key = a metadata type, e.g. `ApexClass`
* value = an array of metadata names, e.g. `['foo_*', 'BarClass']`
*/
const mdMap = new Map<string, string[]>();

const { sourcepath, manifest, metadata, packagenames, apiversion, sourceapiversion, org } = options;
Expand Down Expand Up @@ -110,41 +112,41 @@ export class ComponentSetBuilder {

// Build a Set of metadata entries
metadata.metadataEntries.forEach((rawEntry) => {
const splitEntry = rawEntry.split(':').map((entry) => entry.trim());
const [mdType, mdName] = rawEntry.split(':').map((entry) => entry.trim());
// The registry will throw if it doesn't know what this type is.
registry.getTypeByName(splitEntry[0]);
registry.getTypeByName(mdType);

// Add metadata entries to a map for possible use with an org connection below.
const mdMapEntry = mdMap.get(splitEntry[0]);
const mdMapEntry = mdMap.get(mdType);
if (mdMapEntry) {
mdMapEntry.push(splitEntry[1]);
mdMapEntry.push(mdName);
} else {
mdMap.set(splitEntry[0], [splitEntry[1]]);
mdMap.set(mdType, [mdName]);
}

// this '.*' is a surprisingly valid way to specify a metadata, especially a DEB :sigh:
// https://github.com/salesforcecli/plugin-deploy-retrieve/blob/main/test/nuts/digitalExperienceBundle/constants.ts#L140
// because we're filtering from what we have locally, this won't allow you to retrieve new metadata (on the server only) using the partial wildcard
// to do that, you'd need check the size of the CS created below, see if it's 0, and then query the org for the metadata that matches the regex
// but building a CS from a metadata argument doesn't require an org, so we can't do that here
if (splitEntry[1]?.includes('*') && splitEntry[1]?.length > 1 && !splitEntry[1].includes('.*')) {
if (mdName?.includes('*') && mdName?.length > 1 && !mdName.includes('.*')) {
// get all components of the type, and then filter by the regex of the fullName
ComponentSet.fromSource({
fsPaths: directoryPaths,
include: new ComponentSet([{ type: splitEntry[0], fullName: ComponentSet.WILDCARD }]),
include: new ComponentSet([{ type: mdType, fullName: ComponentSet.WILDCARD }]),
})
.getSourceComponents()
.toArray()
// using minimatch versus RegExp provides better (more expected) matching results
.filter((cs) => minimatch(cs.fullName, splitEntry[1]))
.filter((cs) => minimatch(cs.fullName, mdName))
.map((match) => {
compSetFilter.add(match);
componentSet?.add(match);
});
} else {
const entry = {
type: splitEntry[0],
fullName: splitEntry.length === 1 ? '*' : splitEntry[1],
type: mdType,
fullName: !mdName ? '*' : mdName,
};
// Add to the filtered ComponentSet for resolved source paths,
// and the unfiltered ComponentSet to build the correct manifest.
Expand Down
13 changes: 5 additions & 8 deletions src/resolve/connectionResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ export class ConnectionResolver {
this.connection = connection;
this.registry = registry;
this.logger = Logger.childFromRoot(this.constructor.name);
if (mdTypes?.length) {
// ensure the types passed in are valid per the registry
this.mdTypeNames = mdTypes.filter((t) => this.registry.getTypeByName(t));
} else {
this.mdTypeNames = Object.values(defaultRegistry.types).map((t) => t.name);
}
this.mdTypeNames = mdTypes?.length
? // ensure the types passed in are valid per the registry
mdTypes.filter((t) => this.registry.getTypeByName(t))
: Object.values(defaultRegistry.types).map((t) => t.name);
}

public async resolve(
Expand All @@ -54,9 +52,8 @@ export class ConnectionResolver {
const childrenPromises: Array<Promise<FileProperties[]>> = [];
const componentTypes: Set<MetadataType> = new Set();
const lifecycle = Lifecycle.getInstance();
const componentPromises: Array<Promise<FileProperties[]>> = [];

this.mdTypeNames.forEach((type) => componentPromises.push(this.listMembers({ type })));
const componentPromises = this.mdTypeNames.map((type) => this.listMembers({ type }));

(await Promise.all(componentPromises)).map(async (componentResult) => {
for (const component of componentResult) {
Expand Down

2 comments on commit 4d94595

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 4d94595 Previous: ef9d8f6 Ratio
eda-componentSetCreate-linux 201 ms 200 ms 1.00
eda-sourceToMdapi-linux 5680 ms 4435 ms 1.28
eda-sourceToZip-linux 4520 ms 3958 ms 1.14
eda-mdapiToSource-linux 3234 ms 2805 ms 1.15
lotsOfClasses-componentSetCreate-linux 366 ms 372 ms 0.98
lotsOfClasses-sourceToMdapi-linux 6124 ms 5799 ms 1.06
lotsOfClasses-sourceToZip-linux 5416 ms 4996 ms 1.08
lotsOfClasses-mdapiToSource-linux 3372 ms 3335 ms 1.01
lotsOfClassesOneDir-componentSetCreate-linux 616 ms 645 ms 0.96
lotsOfClassesOneDir-sourceToMdapi-linux 8820 ms 8892 ms 0.99
lotsOfClassesOneDir-sourceToZip-linux 7582 ms 7652 ms 0.99
lotsOfClassesOneDir-mdapiToSource-linux 6067 ms 6104 ms 0.99

This comment was automatically generated by workflow using github-action-benchmark.

@svc-cli-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 4d94595 Previous: ef9d8f6 Ratio
eda-componentSetCreate-win32 473 ms 426 ms 1.11
eda-sourceToMdapi-win32 6031 ms 5831 ms 1.03
eda-sourceToZip-win32 6730 ms 4991 ms 1.35
eda-mdapiToSource-win32 5823 ms 6373 ms 0.91
lotsOfClasses-componentSetCreate-win32 857 ms 963 ms 0.89
lotsOfClasses-sourceToMdapi-win32 10320 ms 10300 ms 1.00
lotsOfClasses-sourceToZip-win32 7257 ms 7527 ms 0.96
lotsOfClasses-mdapiToSource-win32 7560 ms 8154 ms 0.93
lotsOfClassesOneDir-componentSetCreate-win32 1478 ms 1489 ms 0.99
lotsOfClassesOneDir-sourceToMdapi-win32 16415 ms 16017 ms 1.02
lotsOfClassesOneDir-sourceToZip-win32 11488 ms 10639 ms 1.08
lotsOfClassesOneDir-mdapiToSource-win32 13759 ms 13597 ms 1.01

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.