Skip to content

Commit c8d9c44

Browse files
authored
fix: Sort workspaces by last used then name (coder#3943)
1 parent f510f01 commit c8d9c44

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

coderd/workspaces.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"net/http"
1010
"net/url"
11+
"sort"
1112
"strconv"
1213
"strings"
1314
"time"
@@ -913,6 +914,15 @@ func convertWorkspaces(ctx context.Context, db database.Store, workspaces []data
913914
}
914915
apiWorkspaces = append(apiWorkspaces, convertWorkspace(workspace, build, job, template, &owner, &initiator))
915916
}
917+
sort.Slice(apiWorkspaces, func(i, j int) bool {
918+
iw := apiWorkspaces[i]
919+
jw := apiWorkspaces[j]
920+
if jw.LastUsedAt.IsZero() && iw.LastUsedAt.IsZero() {
921+
return iw.Name < jw.Name
922+
}
923+
return iw.LastUsedAt.After(jw.LastUsedAt)
924+
})
925+
916926
return apiWorkspaces, nil
917927
}
918928

0 commit comments

Comments
 (0)