-
Notifications
You must be signed in to change notification settings - Fork 66
Reduce variable count #453
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,25 +63,25 @@ func (b *BundlesAndDepsVariableSource) GetVariables(ctx context.Context) ([]depp | |
var head *catalogmetadata.Bundle | ||
head, bundleQueue = bundleQueue[0], bundleQueue[1:] | ||
|
||
for _, id := range olmvariables.BundleToBundleVariableIDs(head) { | ||
// ignore bundles that have already been processed | ||
if _, ok := visited[id]; ok { | ||
continue | ||
} | ||
visited[id] = struct{}{} | ||
|
||
// get bundle dependencies | ||
dependencies, err := b.filterBundleDependencies(allBundles, head) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not determine dependencies for bundle with id '%s': %w", id, err) | ||
} | ||
id := olmvariables.BundleVariableID(head) | ||
|
||
// add bundle dependencies to queue for processing | ||
bundleQueue = append(bundleQueue, dependencies...) | ||
// ignore bundles that have already been processed | ||
if _, ok := visited[id]; ok { | ||
continue | ||
} | ||
visited[id] = struct{}{} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AFAIK Go doesn't have sets in standard library and as a result using maps for sets is pretty common. But we can do that. However I do not see any sets package in our codebase. What package is it? Edit: is it There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anyway I think it should not be in this PR. Could you please create an issue or PR for this suggesting a pacakge to use? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The k8s API machinery sets package is the one - we use it in basically every other package. Feel free to create the issue if you don't think you can do it here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a fan of small PRs serve one porpuse. Don't want to mix different efforts into this PR. Created #454 for this. |
||
|
||
// create variable | ||
variables = append(variables, olmvariables.NewBundleVariable(id, head, dependencies)) | ||
// get bundle dependencies | ||
dependencies, err := b.filterBundleDependencies(allBundles, head) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not determine dependencies for bundle with id '%s': %w", id, err) | ||
} | ||
|
||
// add bundle dependencies to queue for processing | ||
bundleQueue = append(bundleQueue, dependencies...) | ||
|
||
// create variable | ||
variables = append(variables, olmvariables.NewBundleVariable(head, dependencies)) | ||
} | ||
|
||
return variables, nil | ||
|
@@ -101,11 +101,10 @@ func (b *BundlesAndDepsVariableSource) filterBundleDependencies(allBundles []*ca | |
} | ||
for i := 0; i < len(packageDependencyBundles); i++ { | ||
bundle := packageDependencyBundles[i] | ||
for _, id := range olmvariables.BundleToBundleVariableIDs(bundle) { | ||
if _, ok := added[id]; !ok { | ||
dependencies = append(dependencies, bundle) | ||
added[id] = struct{}{} | ||
} | ||
id := olmvariables.BundleVariableID(bundle) | ||
if _, ok := added[id]; !ok { | ||
dependencies = append(dependencies, bundle) | ||
added[id] = struct{}{} | ||
} | ||
} | ||
} | ||
|
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.
Nit: unrelated to this PR, but we can we change the loop variable to be called
dependency
instead ofbundle
so that it doesn't shadow thebundle
variable passed in as a parameter?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.
I'll submit a follow up PR straight after merging this one.
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.
#455