Stats page should actually be sorted now

This commit is contained in:
Seednode 2023-02-06 12:23:59 -06:00
parent 4fc20f1de8
commit 6a532e5511
2 changed files with 14 additions and 8 deletions

View File

@ -10,7 +10,7 @@ import (
"github.com/spf13/cobra"
)
var Version = "0.36.0"
var Version = "0.36.1"
func init() {
rootCmd.AddCommand(versionCmd)

View File

@ -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