Skip to content

Commit e786ea3

Browse files
committed
go with 2
1 parent 096e2f7 commit e786ea3

File tree

1 file changed

+0
-24
lines changed

1 file changed

+0
-24
lines changed

enterprise/coderd/idpsync.go

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -374,36 +374,12 @@ func (api *API) patchOrganizationIDPSyncMapping(rw http.ResponseWriter, r *http.
374374
}
375375

376376
// Remove entries
377-
378-
// Option 1: the way I was already doing it
379-
for _, mapping := range req.Remove {
380-
for i, it := range newMapping[mapping.Given] {
381-
if it == mapping.Gets {
382-
newMapping[mapping.Given] = append(newMapping[mapping.Given][:i], newMapping[mapping.Given][i+1:]...)
383-
}
384-
}
385-
}
386-
387-
// Option 2: the way you suggested on the PR
388377
for _, mapping := range req.Remove {
389378
newMapping[mapping.Given] = slices.DeleteFunc(newMapping[mapping.Given], func(u uuid.UUID) bool {
390379
return u == mapping.Gets
391380
})
392381
}
393382

394-
// Option 3: this "optimal" but comparatively very noisey and dense version
395-
// Create a map[key][]thingsToRemove
396-
removeMap := make(map[string][]uuid.UUID)
397-
for _, mapping := range req.Remove {
398-
removeMap[mapping.Given] = append(removeMap[mapping.Given], mapping.Gets)
399-
}
400-
// Use `DeleteFunc` to remove anything from the `newMapping` present in `removeMap`
401-
for given, toRemove := range removeMap {
402-
newMapping[given] = slices.DeleteFunc(newMapping[given], func(id uuid.UUID) bool {
403-
return slices.Contains(toRemove, id)
404-
})
405-
}
406-
407383
settings = idpsync.OrganizationSyncSettings{
408384
Field: existing.Field,
409385
Mapping: newMapping,

0 commit comments

Comments
 (0)