@@ -605,8 +605,8 @@ func uniqueSortedUUIDs(uuids []uuid.UUID) []uuid.UUID {
605
605
for id := range set {
606
606
unique = append (unique , id )
607
607
}
608
- slices .SortFunc (unique , func (a , b uuid.UUID ) bool {
609
- return a .String () < b .String ()
608
+ slices .SortFunc (unique , func (a , b uuid.UUID ) int {
609
+ return slice . Ascending ( a .String (), b .String () )
610
610
})
611
611
return unique
612
612
}
@@ -2060,8 +2060,8 @@ func (q *FakeQuerier) GetTemplateDailyInsights(_ context.Context, arg database.G
2060
2060
for templateID := range ds .templateIDSet {
2061
2061
templateIDs = append (templateIDs , templateID )
2062
2062
}
2063
- slices .SortFunc (templateIDs , func (a , b uuid.UUID ) bool {
2064
- return a .String () < b .String ()
2063
+ slices .SortFunc (templateIDs , func (a , b uuid.UUID ) int {
2064
+ return slice . Ascending ( a .String (), b .String () )
2065
2065
})
2066
2066
result = append (result , database.GetTemplateDailyInsightsRow {
2067
2067
StartTime : ds .startTime ,
@@ -2119,8 +2119,8 @@ func (q *FakeQuerier) GetTemplateInsights(_ context.Context, arg database.GetTem
2119
2119
for templateID := range templateIDSet {
2120
2120
templateIDs = append (templateIDs , templateID )
2121
2121
}
2122
- slices .SortFunc (templateIDs , func (a , b uuid.UUID ) bool {
2123
- return a .String () < b .String ()
2122
+ slices .SortFunc (templateIDs , func (a , b uuid.UUID ) int {
2123
+ return slice . Ascending ( a .String (), b .String () )
2124
2124
})
2125
2125
result := database.GetTemplateInsightsRow {
2126
2126
TemplateIDs : templateIDs ,
@@ -2343,13 +2343,16 @@ func (q *FakeQuerier) GetTemplateVersionsByTemplateID(_ context.Context, arg dat
2343
2343
}
2344
2344
2345
2345
// Database orders by created_at
2346
- slices .SortFunc (version , func (a , b database.TemplateVersion ) bool {
2346
+ slices .SortFunc (version , func (a , b database.TemplateVersion ) int {
2347
2347
if a .CreatedAt .Equal (b .CreatedAt ) {
2348
2348
// Technically the postgres database also orders by uuid. So match
2349
2349
// that behavior
2350
- return a .ID .String () < b .ID .String ()
2350
+ return slice . Ascending ( a .ID .String (), b .ID .String () )
2351
2351
}
2352
- return a .CreatedAt .Before (b .CreatedAt )
2352
+ if a .CreatedAt .Before (b .CreatedAt ) {
2353
+ return - 1
2354
+ }
2355
+ return 1
2353
2356
})
2354
2357
2355
2358
if arg .AfterID != uuid .Nil {
@@ -2408,11 +2411,11 @@ func (q *FakeQuerier) GetTemplates(_ context.Context) ([]database.Template, erro
2408
2411
defer q .mutex .RUnlock ()
2409
2412
2410
2413
templates := slices .Clone (q .templates )
2411
- slices .SortFunc (templates , func (i , j database.TemplateTable ) bool {
2412
- if i .Name != j .Name {
2413
- return i . Name < j .Name
2414
+ slices .SortFunc (templates , func (a , b database.TemplateTable ) int {
2415
+ if a .Name != b .Name {
2416
+ return slice . Ascending ( a . Name , b .Name )
2414
2417
}
2415
- return i . ID .String () < j .ID .String ()
2418
+ return slice . Ascending ( a . ID .String (), b .ID .String () )
2416
2419
})
2417
2420
2418
2421
return q .templatesWithUserNoLock (templates ), nil
@@ -2525,8 +2528,8 @@ func (q *FakeQuerier) GetUserLatencyInsights(_ context.Context, arg database.Get
2525
2528
for templateID := range templateIDSet {
2526
2529
templateIDs = append (templateIDs , templateID )
2527
2530
}
2528
- slices .SortFunc (templateIDs , func (a , b uuid.UUID ) bool {
2529
- return a .String () < b .String ()
2531
+ slices .SortFunc (templateIDs , func (a , b uuid.UUID ) int {
2532
+ return slice . Ascending ( a .String (), b .String () )
2530
2533
})
2531
2534
user , err := q .getUserByIDNoLock (userID )
2532
2535
if err != nil {
@@ -2542,8 +2545,8 @@ func (q *FakeQuerier) GetUserLatencyInsights(_ context.Context, arg database.Get
2542
2545
}
2543
2546
rows = append (rows , row )
2544
2547
}
2545
- slices .SortFunc (rows , func (a , b database.GetUserLatencyInsightsRow ) bool {
2546
- return a .UserID .String () < b .UserID .String ()
2548
+ slices .SortFunc (rows , func (a , b database.GetUserLatencyInsightsRow ) int {
2549
+ return slice . Ascending ( a .UserID .String (), b .UserID .String () )
2547
2550
})
2548
2551
2549
2552
return rows , nil
@@ -2590,8 +2593,8 @@ func (q *FakeQuerier) GetUsers(_ context.Context, params database.GetUsersParams
2590
2593
copy (users , q .users )
2591
2594
2592
2595
// Database orders by username
2593
- slices .SortFunc (users , func (a , b database.User ) bool {
2594
- return strings .ToLower (a .Username ) < strings .ToLower (b .Username )
2596
+ slices .SortFunc (users , func (a , b database.User ) int {
2597
+ return slice . Ascending ( strings .ToLower (a .Username ), strings .ToLower (b .Username ) )
2595
2598
})
2596
2599
2597
2600
// Filter out deleted since they should never be returned..
@@ -2799,14 +2802,14 @@ func (q *FakeQuerier) GetWorkspaceAgentStats(_ context.Context, createdAfter tim
2799
2802
2800
2803
agentStatsCreatedAfter := make ([]database.WorkspaceAgentStat , 0 )
2801
2804
for _ , agentStat := range q .workspaceAgentStats {
2802
- if agentStat .CreatedAt .After (createdAfter ) {
2805
+ if agentStat .CreatedAt .After (createdAfter ) || agentStat . CreatedAt . Equal ( createdAfter ) {
2803
2806
agentStatsCreatedAfter = append (agentStatsCreatedAfter , agentStat )
2804
2807
}
2805
2808
}
2806
2809
2807
2810
latestAgentStats := map [uuid.UUID ]database.WorkspaceAgentStat {}
2808
2811
for _ , agentStat := range q .workspaceAgentStats {
2809
- if agentStat .CreatedAt .After (createdAfter ) {
2812
+ if agentStat .CreatedAt .After (createdAfter ) || agentStat . CreatedAt . Equal ( createdAfter ) {
2810
2813
latestAgentStats [agentStat .AgentID ] = agentStat
2811
2814
}
2812
2815
}
@@ -3132,9 +3135,8 @@ func (q *FakeQuerier) GetWorkspaceBuildsByWorkspaceID(_ context.Context,
3132
3135
}
3133
3136
3134
3137
// Order by build_number
3135
- slices .SortFunc (history , func (a , b database.WorkspaceBuild ) bool {
3136
- // use greater than since we want descending order
3137
- return a .BuildNumber > b .BuildNumber
3138
+ slices .SortFunc (history , func (a , b database.WorkspaceBuild ) int {
3139
+ return slice .Descending (a .BuildNumber , b .BuildNumber )
3138
3140
})
3139
3141
3140
3142
if params .AfterID != uuid .Nil {
@@ -3533,8 +3535,14 @@ func (q *FakeQuerier) InsertAuditLog(_ context.Context, arg database.InsertAudit
3533
3535
alog := database .AuditLog (arg )
3534
3536
3535
3537
q .auditLogs = append (q .auditLogs , alog )
3536
- slices .SortFunc (q .auditLogs , func (a , b database.AuditLog ) bool {
3537
- return a .Time .Before (b .Time )
3538
+ slices .SortFunc (q .auditLogs , func (a , b database.AuditLog ) int {
3539
+ if a .Time .Before (b .Time ) {
3540
+ return - 1
3541
+ } else if a .Time .Equal (b .Time ) {
3542
+ return 0
3543
+ } else {
3544
+ return 1
3545
+ }
3538
3546
})
3539
3547
3540
3548
return alog , nil
@@ -5588,11 +5596,11 @@ func (q *FakeQuerier) GetAuthorizedTemplates(ctx context.Context, arg database.G
5588
5596
templates = append (templates , template )
5589
5597
}
5590
5598
if len (templates ) > 0 {
5591
- slices .SortFunc (templates , func (i , j database.Template ) bool {
5592
- if i .Name != j .Name {
5593
- return i . Name < j .Name
5599
+ slices .SortFunc (templates , func (a , b database.Template ) int {
5600
+ if a .Name != b .Name {
5601
+ return slice . Ascending ( a . Name , b .Name )
5594
5602
}
5595
- return i . ID .String () < j .ID .String ()
5603
+ return slice . Ascending ( a . ID .String (), b .ID .String () )
5596
5604
})
5597
5605
return templates , nil
5598
5606
}
0 commit comments