diff --git a/internal/pkg/pluginengine/change_helper.go b/internal/pkg/pluginengine/change_helper.go index bb8e6e0b5..527bbd69c 100644 --- a/internal/pkg/pluginengine/change_helper.go +++ b/internal/pkg/pluginengine/change_helper.go @@ -198,6 +198,8 @@ func topologicalSortChangesInBatch(changes []*Change) ([][]*Change, error) { // get tools from changes tools := getToolsFromChanges(changes) + // map key to changes + changesKeyMap := getChangesKeyMap(changes) batchesOfChanges := make([][]*Change, 0) @@ -216,10 +218,9 @@ func topologicalSortChangesInBatch(changes []*Change) ([][]*Change, error) { changesOneBatch := make([]*Change, 0) // for each tool in the batch, find the change that matches it for _, tool := range batch { - for _, change := range changes { - if change.Tool.Key() == tool.Key() { - changesOneBatch = append(changesOneBatch, change) - } + // only add the change that has the tool match with it + if change, ok := changesKeyMap[tool.Key()]; ok { + changesOneBatch = append(changesOneBatch, change) } } @@ -247,3 +248,11 @@ func getToolsFromChanges(changes []*Change) []configloader.Tool { return tools } + +func getChangesKeyMap(changes []*Change) map[string]*Change { + changesKeyMap := make(map[string]*Change) + for _, change := range changes { + changesKeyMap[change.Tool.Key()] = change + } + return changesKeyMap +}