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(pipelines): graphnode dependencies can have duplicates #18450

Merged
merged 5 commits into from
Jan 19, 2022
Merged

fix(pipelines): graphnode dependencies can have duplicates #18450

merged 5 commits into from
Jan 19, 2022

Conversation

kaizencc
Copy link
Contributor

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

@kaizencc kaizencc requested a review from rix0rrr January 15, 2022 03:16
@gitpod-io
Copy link

gitpod-io bot commented Jan 15, 2022

@github-actions github-actions bot added the @aws-cdk/pipelines CDK Pipelines library label Jan 15, 2022
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jan 15, 2022
Copy link
Contributor

@rix0rrr rix0rrr left a 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

Comment on lines 387 to 391
dependencies.sort((a, b) => a.uniqueId.localeCompare(b.uniqueId));
return dedupeGraphNodes(dependencies);
}

Copy link
Contributor

@rix0rrr rix0rrr Jan 18, 2022

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);
    }
  }
}

Copy link
Contributor

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));

@rix0rrr rix0rrr added the pr/do-not-merge This PR should not be merged at this time. label Jan 18, 2022
@kaizencc kaizencc removed the pr/do-not-merge This PR should not be merged at this time. label Jan 18, 2022
@mergify
Copy link
Contributor

mergify bot commented Jan 18, 2022

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-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject89A8053A-LhjRyN9kxr8o
  • Commit ID: a2e276b
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 2b0b5ea into aws:master Jan 19, 2022
@mergify
Copy link
Contributor

mergify bot commented Jan 19, 2022

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).

TikiTDO pushed a commit to TikiTDO/aws-cdk that referenced this pull request Feb 21, 2022
`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*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/pipelines CDK Pipelines library contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants