Skip to content

Commit bf218e9

Browse files
committed
uniq
1 parent 05d7a2c commit bf218e9

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
@@ -562,6 +562,21 @@ func isNotNull(v interface{}) bool {
562562
// these methods remain unimplemented in the FakeQuerier.
563563
var ErrUnimplemented = xerrors.New("unimplemented")
564564

565+
func uniqueSortedUUIDs(uuids []uuid.UUID) []uuid.UUID {
566+
set := make(map[uuid.UUID]struct{})
567+
for _, id := range uuids {
568+
set[id] = struct{}{}
569+
}
570+
unique := make([]uuid.UUID, 0, len(set))
571+
for id := range set {
572+
unique = append(unique, id)
573+
}
574+
slices.SortFunc(unique, func(a, b uuid.UUID) bool {
575+
return a.String() < b.String()
576+
})
577+
return unique
578+
}
579+
565580
func (*FakeQuerier) AcquireLock(_ context.Context, _ int64) error {
566581
return xerrors.New("AcquireLock must only be called within a transaction")
567582
}
@@ -2147,7 +2162,7 @@ func (q *FakeQuerier) GetTemplateParameterInsights(ctx context.Context, arg data
21472162
for value, count := range counts[key] {
21482163
rows = append(rows, database.GetTemplateParameterInsightsRow{
21492164
Num: utp.Num,
2150-
TemplateIDs: utp.TemplateIDs,
2165+
TemplateIDs: uniqueSortedUUIDs(utp.TemplateIDs),
21512166
Name: utp.Name,
21522167
DisplayName: utp.DisplayName,
21532168
Description: utp.Description,

0 commit comments

Comments
 (0)