Stats page should actually be sorted now
This commit is contained in:
parent
4fc20f1de8
commit
6a532e5511
|
@ -10,7 +10,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var Version = "0.36.0"
|
||||
var Version = "0.36.1"
|
||||
|
||||
func init() {
|
||||
rootCmd.AddCommand(versionCmd)
|
||||
|
|
20
cmd/web.go
20
cmd/web.go
|
@ -183,20 +183,26 @@ func (s *ServeStats) incrementCounter(image string, timestamp time.Time, filesiz
|
|||
func (s *ServeStats) ListImages() ([]byte, error) {
|
||||
s.mutex.RLock()
|
||||
|
||||
sortedList := s.list
|
||||
sortedList := &ServeStats{
|
||||
mutex: sync.RWMutex{},
|
||||
list: s.list,
|
||||
count: s.count,
|
||||
size: s.size,
|
||||
times: s.times,
|
||||
}
|
||||
|
||||
sort.SliceStable(sortedList, func(p, q int) bool {
|
||||
return sortedList[p] < sortedList[q]
|
||||
s.mutex.RUnlock()
|
||||
|
||||
sort.SliceStable(sortedList.list, func(p, q int) bool {
|
||||
return sortedList.list[p] < sortedList.list[q]
|
||||
})
|
||||
|
||||
a := []timesServed{}
|
||||
|
||||
for _, image := range s.list {
|
||||
a = append(a, timesServed{image, s.count[image], s.size[image], s.times[image]})
|
||||
for _, image := range sortedList.list {
|
||||
a = append(a, timesServed{image, sortedList.count[image], sortedList.size[image], sortedList.times[image]})
|
||||
}
|
||||
|
||||
s.mutex.RUnlock()
|
||||
|
||||
r, err := json.MarshalIndent(a, "", " ")
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
|
|
Loading…
Reference in New Issue