Skip to content

Commit

Permalink
chore: code review II
Browse files Browse the repository at this point in the history
  • Loading branch information
WillieRuemmele committed Sep 9, 2024
1 parent 6a34e06 commit a337c83
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/convert/transformers/decomposedPermissionSetTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export class DecomposedPermissionSetTransformer extends BaseMetadataTransformer
.map((c) => toInfoContainer(mergeWith)(component)(c.childType)(c.tagValue as JsonMap))
.filter(forceIgnoreAllowsComponent(forceIgnore));

const writeInfosForChildren = getAndCombineChildWriteInfos(
const writeInfosForChildren = combineChildWriteInfos(
[
// children whose type don't have a directory assigned will be written to the top level, separate them into individual WriteInfo[] with only one entry
// a [WriteInfo] with one entry, will result in one file
Expand Down Expand Up @@ -166,18 +166,32 @@ const getDefaultOutput = (component: MetadataComponent): SourcePath => {
return join(calculateRelativePath('source')({ self: parent?.type ?? type })(fullName)(baseName), output);
};

const getAndCombineChildWriteInfos = (
const buildSource = (parentType: string, info: InfoContainer[], childDirectories: Array<[string, string]>): JsToXml =>
new JsToXml({
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
[parentType]: Object.assign(
{},
...info.map((i) => ({
[childDirectories
// the child tag values correspond to the parents directories, not the names , classAccess => <classAccesses>
// find the value that matches, and use the key e[0]=value
.find((e) => e[1] === i.childComponent.type.name.toLowerCase())
?.at(0) ?? '']: i.value,
}))
),
});
const combineChildWriteInfos = (
containers: InfoContainer[][],
stateSetter: StateSetter,
childrenOfMergeComponent: ComponentSet
): WriteInfo[] => {
// aggregator write info, will be returned at the end
const writeInfos: WriteInfo[] = [];
containers.forEach((c) => {
containers.forEach((infoContainers) => {
// we have multiple InfoContainers, build a map of output file => file content
// this is how we'll combine multiple children into one file
const nameWriteInfoMap = new Map<string, InfoContainer[]>();
c.map((info) =>
infoContainers.map((info) =>
nameWriteInfoMap.has(info.entryName)
? nameWriteInfoMap.get(info.entryName)!.push(info)
: nameWriteInfoMap.set(info.entryName, [info])
Expand All @@ -188,19 +202,7 @@ const getAndCombineChildWriteInfos = (
const childDirectories = Object.entries(
info[0].parentComponent.type.children?.directories as Record<string, string>
);
const source = new JsToXml({
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
[info[0].parentComponent.type.name]: Object.assign(
{},
...info.map((i) => ({
[childDirectories
// the child tag values correspond to the parents directories, not the names , classAccess => <classAccesses>
// find the value that matches, and use the key e[0]=value
.find((e) => e[1] === i.childComponent.type.name.toLowerCase())
?.at(0) ?? '']: i.value,
}))
),
});
const source = buildSource(info[0].parentComponent.type.name, info, childDirectories);
// if there's nothing to merge with, push write operation now to default location
const childInfo = info[0].childComponent;
if (!info[0].mergeWith) {
Expand Down

2 comments on commit a337c83

@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: a337c83 Previous: a91ff29 Ratio
eda-componentSetCreate-linux 237 ms 243 ms 0.98
eda-sourceToMdapi-linux 2401 ms 2338 ms 1.03
eda-sourceToZip-linux 2010 ms 1983 ms 1.01
eda-mdapiToSource-linux 2945 ms 3151 ms 0.93
lotsOfClasses-componentSetCreate-linux 490 ms 434 ms 1.13
lotsOfClasses-sourceToMdapi-linux 3693 ms 3786 ms 0.98
lotsOfClasses-sourceToZip-linux 3314 ms 3355 ms 0.99
lotsOfClasses-mdapiToSource-linux 3624 ms 3694 ms 0.98
lotsOfClassesOneDir-componentSetCreate-linux 771 ms 763 ms 1.01
lotsOfClassesOneDir-sourceToMdapi-linux 6657 ms 6764 ms 0.98
lotsOfClassesOneDir-sourceToZip-linux 5876 ms 5959 ms 0.99
lotsOfClassesOneDir-mdapiToSource-linux 6625 ms 6764 ms 0.98

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: a337c83 Previous: a91ff29 Ratio
eda-componentSetCreate-win32 677 ms 702 ms 0.96
eda-sourceToMdapi-win32 4630 ms 4353 ms 1.06
eda-sourceToZip-win32 3216 ms 3267 ms 0.98
eda-mdapiToSource-win32 6162 ms 6168 ms 1.00
lotsOfClasses-componentSetCreate-win32 1343 ms 1342 ms 1.00
lotsOfClasses-sourceToMdapi-win32 8507 ms 7999 ms 1.06
lotsOfClasses-sourceToZip-win32 5392 ms 5197 ms 1.04
lotsOfClasses-mdapiToSource-win32 8406 ms 7861 ms 1.07
lotsOfClassesOneDir-componentSetCreate-win32 2364 ms 2162 ms 1.09
lotsOfClassesOneDir-sourceToMdapi-win32 14485 ms 13870 ms 1.04
lotsOfClassesOneDir-sourceToZip-win32 9204 ms 9109 ms 1.01
lotsOfClassesOneDir-mdapiToSource-win32 14114 ms 14342 ms 0.98

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

Please sign in to comment.