From aa0eec16ab0d0d473d06d2505a42680cdcb725a4 Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Thu, 28 Mar 2024 10:13:07 -0700 Subject: [PATCH] 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. --- cmd/data-usage-cache.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/cmd/data-usage-cache.go b/cmd/data-usage-cache.go index 8d5e13f13..15ea11a0f 100644 --- a/cmd/data-usage-cache.go +++ b/cmd/data-usage-cache.go @@ -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 }