Remove empty replication stats when sending update (#19375)

When sending update and there is no replication stats - remove the struct.

Will remove an unneeded alloc on the receiver.
This commit is contained in:
Klaus Post 2024-03-28 10:13:07 -07:00 committed by GitHub
parent d63e603040
commit aa0eec16ab
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -191,6 +191,22 @@ type replicationAllStatsV1 struct {
ReplicaCount uint64 `msg:"ReplicaCount,omitempty"`
}
// empty returns true if the replicationAllStats is empty (contains no entries).
func (r *replicationAllStats) empty() bool {
if r == nil {
return true
}
if r.ReplicaSize != 0 || r.ReplicaCount != 0 {
return false
}
for _, v := range r.Targets {
if !v.Empty() {
return false
}
}
return true
}
// clone creates a deep-copy clone.
func (r *replicationAllStats) clone() *replicationAllStats {
if r == nil {
@ -899,6 +915,9 @@ func (d *dataUsageCache) sizeRecursive(path string) *dataUsageEntry {
return root
}
flat := d.flatten(*root)
if flat.ReplicationStats.empty() {
flat.ReplicationStats = nil
}
return &flat
}