Skip to content

Commit 2495537

Browse files
refactor to not iterate through all verticies while iterating through all verticies
1 parent 1c9c5c7 commit 2495537

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

internal/terraform/transform_provider.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,14 @@ func (t *CloseProviderTransformer) Transform(g *Graph) error {
285285
g.Connect(dag.BasicEdge(closer, p))
286286
}
287287

288+
// We collect all action nodes to use later
289+
actionNodes := []*nodeExpandActionDeclaration{}
290+
288291
// Now look for all provider consumers and connect them to the appropriate closers.
289292
for _, v := range g.Vertices() {
293+
if actionNode, ok := v.(*nodeExpandActionDeclaration); ok {
294+
actionNodes = append(actionNodes, actionNode)
295+
}
290296
pc, ok := v.(GraphNodeProviderConsumer)
291297
if !ok {
292298
continue
@@ -321,13 +327,11 @@ func (t *CloseProviderTransformer) Transform(g *Graph) error {
321327
// It should have been resolved already by the ProviderTransformer.
322328
actions := apc.Actions()
323329
actionProviders := []addrs.AbsProviderConfig{}
324-
for _, v2 := range g.Vertices() {
325-
if actionNode, ok := v2.(*nodeExpandActionDeclaration); ok {
326-
// This is an action node, so check if it matches an action
327-
for _, action := range actions {
328-
if actionNode.ActionAddr().Equal(action) {
329-
actionProviders = append(actionProviders, actionNode.ResolvedProvider)
330-
}
330+
for _, actionNode := range actionNodes {
331+
// This is an action node, so check if it matches an action
332+
for _, action := range actions {
333+
if actionNode.ActionAddr().Equal(action) {
334+
actionProviders = append(actionProviders, actionNode.ResolvedProvider)
331335
}
332336
}
333337
}

0 commit comments

Comments
 (0)