forked from pachyderm/pachyderm
/
sorting.go
41 lines (31 loc) · 1.2 KB
/
sorting.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package server
import (
"sort"
"go.pedge.io/proto/time"
"github.com/pachyderm/pachyderm/src/server/pps/persist"
)
// TODO: this should be a call through the actual persist storage
//
// This does not work:
//
// func(term gorethink.Term) gorethink.Term {
// return term.OrderBy(gorethink.Desc("created_at"))
// }
func sortJobInfosByTimestampDesc(s []*persist.JobInfo) {
sort.Sort(jobInfosByTimestampDesc(s))
}
type jobInfosByTimestampDesc []*persist.JobInfo
func (s jobInfosByTimestampDesc) Len() int { return len(s) }
func (s jobInfosByTimestampDesc) Swap(i int, j int) { s[i], s[j] = s[j], s[i] }
func (s jobInfosByTimestampDesc) Less(i int, j int) bool {
return prototime.TimestampLess(s[j].CreatedAt, s[i].CreatedAt)
}
func sortPipelineInfosByTimestampDesc(s []*persist.PipelineInfo) {
sort.Sort(pipelineInfosByTimestampDesc(s))
}
type pipelineInfosByTimestampDesc []*persist.PipelineInfo
func (s pipelineInfosByTimestampDesc) Len() int { return len(s) }
func (s pipelineInfosByTimestampDesc) Swap(i int, j int) { s[i], s[j] = s[j], s[i] }
func (s pipelineInfosByTimestampDesc) Less(i int, j int) bool {
return prototime.TimestampLess(s[j].CreatedAt, s[i].CreatedAt)
}