Skip to content

Commit 2a79467

Browse files
committed
PR feedback optimizations
1 parent ae7edd7 commit 2a79467

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

service/internal/subjectmappingbuiltin/subject_mapping_builtin_actions.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package subjectmappingbuiltin
22

33
import (
44
"fmt"
5+
"maps"
56
"slices"
67
"strings"
78

@@ -19,7 +20,7 @@ func EvaluateSubjectMappingMultipleEntitiesWithActions(
1920
attributeMappings map[string]*attributes.GetAttributeValuesByFqnsResponse_AttributeAndValue,
2021
entityRepresentations []*entityresolutionV2.EntityRepresentation,
2122
) (EntityIDsToEntitlements, error) {
22-
results := make(map[string]AttributeValueFQNsToActions)
23+
results := make(map[string]AttributeValueFQNsToActions, len(entityRepresentations))
2324
for _, er := range entityRepresentations {
2425
entitlements, err := EvaluateSubjectMappingsWithActions(attributeMappings, er)
2526
if err != nil {
@@ -71,13 +72,12 @@ func EvaluateSubjectMappingsWithActions(
7172
actions := subjectMapping.GetActions()
7273

7374
// Cache each action by name to deduplicate
75+
m := make(map[string]*policy.Action, len(actions))
7476
for _, action := range actions {
75-
if !slices.ContainsFunc(entitlementsSet[valueFQN], func(a *policy.Action) bool {
76-
return strings.EqualFold(a.GetName(), action.GetName())
77-
}) {
78-
entitlementsSet[valueFQN] = append(entitlementsSet[valueFQN], action)
79-
}
77+
m[strings.ToLower(action.GetName())] = action
78+
8079
}
80+
entitlementsSet[valueFQN] = append(entitlementsSet[valueFQN], slices.Collect(maps.Values(m))...)
8181
}
8282
}
8383
}

0 commit comments

Comments
 (0)