accounting: stabilize display order of transfers on Windows

Before this change we sorted transfers in the stats list solely on
time started. However if --check-first was in use then lots of
transfers could be started in the same millisecond. Because Windows
time resolution is only 1mS this caused the entries to sort equal and
bounce around in the list.

This change fixes the sort so that if the time is equal it uses the
name which should stabilize the order.

Fixes #4599
This commit is contained in:
Nick Craig-Wood 2020-09-18 12:30:01 +01:00
parent ab88a3341f
commit 433b73a5a8

View File

@ -72,8 +72,16 @@ func (tm *transferMap) _sortedSlice() []*Transfer {
for _, tr := range tm.items { for _, tr := range tm.items {
s = append(s, tr) s = append(s, tr)
} }
// sort by time first and if equal by name. Note that the relatively
// low time resolution on Windows can cause equal times.
sort.Slice(s, func(i, j int) bool { sort.Slice(s, func(i, j int) bool {
return s[i].startedAt.Before(s[j].startedAt) a, b := s[i], s[j]
if a.startedAt.Before(b.startedAt) {
return true
} else if !a.startedAt.Equal(b.startedAt) {
return false
}
return a.remote < b.remote
}) })
return s return s
} }