Skip to content

Commit 355c9b5

Browse files
committed
uniq
1 parent 05d7a2c commit 355c9b5

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

coderd/database/dbfake/dbfake.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -2147,7 +2147,7 @@ func (q *FakeQuerier) GetTemplateParameterInsights(ctx context.Context, arg data
21472147
for value, count := range counts[key] {
21482148
rows = append(rows, database.GetTemplateParameterInsightsRow{
21492149
Num: utp.Num,
2150-
TemplateIDs: utp.TemplateIDs,
2150+
TemplateIDs: uniqueSortedUUIDs(utp.TemplateIDs),
21512151
Name: utp.Name,
21522152
DisplayName: utp.DisplayName,
21532153
Description: utp.Description,
@@ -2161,6 +2161,21 @@ func (q *FakeQuerier) GetTemplateParameterInsights(ctx context.Context, arg data
21612161
return rows, nil
21622162
}
21632163

2164+
func uniqueSortedUUIDs(uuids []uuid.UUID) []uuid.UUID {
2165+
set := make(map[uuid.UUID]struct{})
2166+
for _, id := range uuids {
2167+
set[id] = struct{}{}
2168+
}
2169+
unique := make([]uuid.UUID, 0, len(set))
2170+
for id := range set {
2171+
unique = append(unique, id)
2172+
}
2173+
slices.SortFunc(unique, func(a, b uuid.UUID) bool {
2174+
return a.String() < b.String()
2175+
})
2176+
return unique
2177+
}
2178+
21642179
func (q *FakeQuerier) GetTemplateVersionByID(ctx context.Context, templateVersionID uuid.UUID) (database.TemplateVersion, error) {
21652180
q.mutex.RLock()
21662181
defer q.mutex.RUnlock()

0 commit comments

Comments
 (0)