-
Notifications
You must be signed in to change notification settings - Fork 4k
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(pipelines): graphnode dependencies can have duplicates #18450
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
approved but consider simplifying a little
dependencies.sort((a, b) => a.uniqueId.localeCompare(b.uniqueId)); | ||
return dedupeGraphNodes(dependencies); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this isn't wrong, it feels overly complex in this case.
Why don't we use the built-in Set
?
function deduplicateDependencies<A>(dependencies: GraphNode<A>[]) {
const ret = new Array<GraphNode<A>>();
const seen = new Set<GraphNode<A>>();
for (const dep of dependencies) {
if (seen.has(dep)) { continue; }
seen.add(dep);
ret.push(dep);
}
return ret;
}
Or if you want to be fancy, with a generator helper function (to save the accumulator variable ret
):
function deduplicateDependencies<A>(dependencies: GraphNode<A>[]) {
const seen = new Set<GraphNode<A>>();
return Array.from(generate());
function* generate() {
for (const dep of dependencies) {
if (seen.has(dep)) { continue; }
seen.add(dep);
yield dep;
ret.push(dep);
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even better what you said:
return Array.from(new Set(dependencies));
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
`GraphNode.allDeps` allows duplicate dependencies to be returned. This does not have any affect on the performance of the pipelines module, but looks ugly. This was noticed in cdklabs/cdk-pipelines-github#67, where the dependencies are written out to the `deploy.yaml` file. I did not change the underlying `GraphNode.dependencies` structure to be a set (although I think it should) because I feel like that is a breaking change. So instead I've preserved the structure of the API and deduplicated the list of GraphNodes. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
GraphNode.allDeps
allows duplicate dependencies to be returned. This does not have any affect on the performance of the pipelines module, but looks ugly. This was noticed in cdklabs/cdk-pipelines-github#67, where the dependencies are written out to thedeploy.yaml
file.I did not change the underlying
GraphNode.dependencies
structure to be a set (although I think it should) because I feel like that is a breaking change. So instead I've preserved the structure of the API and deduplicated the list of GraphNodes.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license