@@ -15,7 +15,6 @@ import (
15
15
16
16
"github.com/google/uuid"
17
17
"github.com/lib/pq"
18
- "golang.org/x/exp/constraints"
19
18
"golang.org/x/exp/maps"
20
19
"golang.org/x/exp/slices"
21
20
"golang.org/x/xerrors"
@@ -607,7 +606,7 @@ func uniqueSortedUUIDs(uuids []uuid.UUID) []uuid.UUID {
607
606
unique = append (unique , id )
608
607
}
609
608
slices .SortFunc (unique , func (a , b uuid.UUID ) int {
610
- return orderingAscend ( a , b )
609
+ return slice . Ascending ( a . String () , b . String () )
611
610
})
612
611
return unique
613
612
}
@@ -2061,8 +2060,8 @@ func (q *FakeQuerier) GetTemplateDailyInsights(_ context.Context, arg database.G
2061
2060
for templateID := range ds .templateIDSet {
2062
2061
templateIDs = append (templateIDs , templateID )
2063
2062
}
2064
- slices .SortFunc (templateIDs , func (a , b uuid.UUID ) bool {
2065
- return a .String () < b .String ()
2063
+ slices .SortFunc (templateIDs , func (a , b uuid.UUID ) int {
2064
+ return slice . Ascending ( a .String (), b .String () )
2066
2065
})
2067
2066
result = append (result , database.GetTemplateDailyInsightsRow {
2068
2067
StartTime : ds .startTime ,
@@ -2120,8 +2119,8 @@ func (q *FakeQuerier) GetTemplateInsights(_ context.Context, arg database.GetTem
2120
2119
for templateID := range templateIDSet {
2121
2120
templateIDs = append (templateIDs , templateID )
2122
2121
}
2123
- slices .SortFunc (templateIDs , func (a , b uuid.UUID ) bool {
2124
- return a .String () < b .String ()
2122
+ slices .SortFunc (templateIDs , func (a , b uuid.UUID ) int {
2123
+ return slice . Ascending ( a .String (), b .String () )
2125
2124
})
2126
2125
result := database.GetTemplateInsightsRow {
2127
2126
TemplateIDs : templateIDs ,
@@ -2342,13 +2341,17 @@ func (q *FakeQuerier) GetTemplateVersionsByTemplateID(_ context.Context, arg dat
2342
2341
}
2343
2342
2344
2343
// Database orders by created_at
2345
- slices .SortFunc (version , func (a , b database.TemplateVersion ) bool {
2344
+ slices .SortFunc (version , func (a , b database.TemplateVersion ) int {
2346
2345
if a .CreatedAt .Equal (b .CreatedAt ) {
2347
2346
// Technically the postgres database also orders by uuid. So match
2348
2347
// that behavior
2349
- return a .ID .String () < b .ID .String ()
2348
+ return slice .Ascending (a .ID .String (), b .ID .String ())
2349
+ }
2350
+ if a .CreatedAt .Before (b .CreatedAt ) {
2351
+ return - 1
2352
+ } else {
2353
+ return 1
2350
2354
}
2351
- return a .CreatedAt .Before (b .CreatedAt )
2352
2355
})
2353
2356
2354
2357
if arg .AfterID != uuid .Nil {
@@ -2407,11 +2410,11 @@ func (q *FakeQuerier) GetTemplates(_ context.Context) ([]database.Template, erro
2407
2410
defer q .mutex .RUnlock ()
2408
2411
2409
2412
templates := slices .Clone (q .templates )
2410
- slices .SortFunc (templates , func (i , j database.TemplateTable ) bool {
2411
- if i .Name != j .Name {
2412
- return i . Name < j .Name
2413
+ slices .SortFunc (templates , func (a , b database.TemplateTable ) int {
2414
+ if a .Name != b .Name {
2415
+ return slice . Ascending ( a . Name , b .Name )
2413
2416
}
2414
- return i . ID .String () < j .ID .String ()
2417
+ return slice . Ascending ( a . ID .String (), b .ID .String () )
2415
2418
})
2416
2419
2417
2420
return q .templatesWithUserNoLock (templates ), nil
@@ -2524,8 +2527,8 @@ func (q *FakeQuerier) GetUserLatencyInsights(_ context.Context, arg database.Get
2524
2527
for templateID := range templateIDSet {
2525
2528
templateIDs = append (templateIDs , templateID )
2526
2529
}
2527
- slices .SortFunc (templateIDs , func (a , b uuid.UUID ) bool {
2528
- return a .String () < b .String ()
2530
+ slices .SortFunc (templateIDs , func (a , b uuid.UUID ) int {
2531
+ return slice . Ascending ( a .String (), b .String () )
2529
2532
})
2530
2533
user , err := q .getUserByIDNoLock (userID )
2531
2534
if err != nil {
@@ -2541,8 +2544,8 @@ func (q *FakeQuerier) GetUserLatencyInsights(_ context.Context, arg database.Get
2541
2544
}
2542
2545
rows = append (rows , row )
2543
2546
}
2544
- slices .SortFunc (rows , func (a , b database.GetUserLatencyInsightsRow ) bool {
2545
- return a .UserID .String () < b .UserID .String ()
2547
+ slices .SortFunc (rows , func (a , b database.GetUserLatencyInsightsRow ) int {
2548
+ return slice . Ascending ( a .UserID .String (), b .UserID .String () )
2546
2549
})
2547
2550
2548
2551
return rows , nil
@@ -2589,8 +2592,8 @@ func (q *FakeQuerier) GetUsers(_ context.Context, params database.GetUsersParams
2589
2592
copy (users , q .users )
2590
2593
2591
2594
// Database orders by username
2592
- slices .SortFunc (users , func (a , b database.User ) bool {
2593
- return strings . ToLower (a .Username ) < strings . ToLower ( b .Username )
2595
+ slices .SortFunc (users , func (a , b database.User ) int {
2596
+ return slice . Ascending (a .Username , b .Username )
2594
2597
})
2595
2598
2596
2599
// Filter out deleted since they should never be returned..
@@ -3128,7 +3131,8 @@ func (q *FakeQuerier) GetWorkspaceBuildsByWorkspaceID(_ context.Context,
3128
3131
3129
3132
// Order by build_number
3130
3133
slices .SortFunc (history , func (a , b database.WorkspaceBuild ) int {
3131
- return orderingDescend (a .BuildNumber , b .BuildNumber )
3134
+ return slice .Descending (a .BuildNumber , b .BuildNumber )
3135
+
3132
3136
})
3133
3137
3134
3138
if params .AfterID != uuid .Nil {
@@ -5488,11 +5492,11 @@ func (q *FakeQuerier) GetAuthorizedTemplates(ctx context.Context, arg database.G
5488
5492
templates = append (templates , template )
5489
5493
}
5490
5494
if len (templates ) > 0 {
5491
- slices .SortFunc (templates , func (i , j database.Template ) bool {
5492
- if i .Name != j .Name {
5493
- return i . Name < j .Name
5495
+ slices .SortFunc (templates , func (a , b database.Template ) int {
5496
+ if a .Name != b .Name {
5497
+ return slice . Ascending ( a . Name , b .Name )
5494
5498
}
5495
- return i . ID .String () < j .ID .String ()
5499
+ return slice . Ascending ( a . ID .String (), b .ID .String () )
5496
5500
})
5497
5501
return templates , nil
5498
5502
}
@@ -5865,17 +5869,3 @@ func (q *FakeQuerier) GetAuthorizedUsers(ctx context.Context, arg database.GetUs
5865
5869
}
5866
5870
return filteredUsers , nil
5867
5871
}
5868
-
5869
- func orderingAscend [E constraints.Ordered ](a , b E ) int {
5870
- if a < b {
5871
- return - 1
5872
- } else if a == b {
5873
- return 0
5874
- } else {
5875
- return 1
5876
- }
5877
- }
5878
-
5879
- func orderingDescend [E constraints.Ordered ](a , b E ) int {
5880
- return - orderingAscend [E ](a , b )
5881
- }
0 commit comments