1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-11 18:20:28 +09:00

Update sorting and add spaceId

This commit is contained in:
mcrakhman 2023-11-21 09:38:24 +01:00
parent b45d81a296
commit 4c87978627
No known key found for this signature in database
GPG key ID: DED12CFEF5B8396B

View file

@ -29,8 +29,8 @@ type spaceQueueStat struct {
}
type SummaryStat struct {
QueueStats []spaceQueueStat `json:"sorted_stats"`
TotalSize int `json:"total_size"`
QueueStats []spaceQueueStat `json:"sorted_stats"`
}
type peerStat struct {
@ -91,7 +91,19 @@ func (r *requestStat) QueueStat() spaceQueueStat {
stat.PeerId = peerId
peerStats = append(peerStats, stat)
}
slices.SortFunc(peerStats, func(first, second peerStat) int {
firstTotalSize := first.QueueSize + first.SyncSize
secondTotalSize := second.QueueSize + second.SyncSize
if firstTotalSize > secondTotalSize {
return 1
} else if firstTotalSize == secondTotalSize {
return 0
} else {
return -1
}
})
return spaceQueueStat{
SpaceId: r.spaceId,
TotalSize: totalSize,
PeerStats: peerStats,
}