checks: don't iterate through all the nodes when there is nothing to search for (#32927)

This commit is contained in:
Liam Cervante 2023-03-28 18:14:27 +02:00 committed by GitHub
parent 5f97f88025
commit c06db2aadd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -70,23 +70,28 @@ func (t *checkTransformer) transform(g *Graph, cfg *configs.Config, allNodes []d
// actual checks. // actual checks.
g.Connect(dag.BasicEdge(expand, report)) g.Connect(dag.BasicEdge(expand, report))
// This part ensures we report our checks before our nested data if check.DataResource != nil {
// block executes and attempts to report on a check. // If we have a nested data source, we need to make sure we
for _, other := range allNodes { // also report the check before the data source executes.
if resource, isResource := other.(GraphNodeConfigResource); isResource { //
resourceAddr := resource.ResourceAddr() // We loop through all the nodes in the graph to find the one
if !resourceAddr.Module.Equal(moduleAddr) { // that contains our data source and connect it.
// This resource isn't in the same module as our check for _, other := range allNodes {
// so skip it. if resource, isResource := other.(GraphNodeConfigResource); isResource {
continue resourceAddr := resource.ResourceAddr()
} if !resourceAddr.Module.Equal(moduleAddr) {
// This resource isn't in the same module as our check
// so skip it.
continue
}
resourceCfg := cfg.Module.ResourceByAddr(resourceAddr.Resource) resourceCfg := cfg.Module.ResourceByAddr(resourceAddr.Resource)
if resourceCfg != nil && resourceCfg.Container != nil && resourceCfg.Container.Accessible(check.Addr()) { if resourceCfg != nil && resourceCfg.Container != nil && resourceCfg.Container.Accessible(check.Addr()) {
// Make sure we report our checks before we execute any // Make sure we report our checks before we execute any
// embedded data resource. // embedded data resource.
g.Connect(dag.BasicEdge(other, report)) g.Connect(dag.BasicEdge(other, report))
continue continue
}
} }
} }
} }