fix: Sort workspaces by last used then name (#3943)

This commit is contained in:
Kyle Carberry
2022-09-07 21:16:53 +00:00
committed by GitHub
parent f510f01768
commit c8d9c44aba
+10
View File
@@ -8,6 +8,7 @@ import (
"fmt"
"net/http"
"net/url"
"sort"
"strconv"
"strings"
"time"
@@ -913,6 +914,15 @@ func convertWorkspaces(ctx context.Context, db database.Store, workspaces []data
}
apiWorkspaces = append(apiWorkspaces, convertWorkspace(workspace, build, job, template, &owner, &initiator))
}
sort.Slice(apiWorkspaces, func(i, j int) bool {
iw := apiWorkspaces[i]
jw := apiWorkspaces[j]
if jw.LastUsedAt.IsZero() && iw.LastUsedAt.IsZero() {
return iw.Name < jw.Name
}
return iw.LastUsedAt.After(jw.LastUsedAt)
})
return apiWorkspaces, nil
}