1
0
mirror of https://github.com/rancher/steve.git synced 2025-10-20 23:08:48 +00:00

Implement custom DeepCopy for Count

This commit is contained in:
Jonathan Crowther
2024-03-01 11:56:18 -05:00
parent 0e74495395
commit cec59c5a61
4 changed files with 12 additions and 5 deletions

View File

@@ -4,7 +4,6 @@ import (
"time"
"github.com/rancher/apiserver/pkg/types"
"golang.design/x/reflect"
)
// debounceDuration determines how long events will be held before they are sent to the consumer
@@ -50,7 +49,7 @@ func debounceCounts(result chan types.APIEvent, input chan Count) {
}
case <-t.C:
if currentCount != nil {
result <- toAPIEvent(reflect.DeepCopy(*currentCount))
result <- toAPIEvent(*currentCount.DeepCopy())
currentCount = nil
}
}

View File

@@ -48,6 +48,17 @@ type Count struct {
Counts map[string]ItemCount `json:"counts"`
}
func (c *Count) DeepCopy() *Count {
r := *c
if r.Counts != nil {
r.Counts = map[string]ItemCount{}
for k, v := range c.Counts {
r.Counts[k] = *v.DeepCopy()
}
}
return &r
}
type Summary struct {
Count int `json:"count,omitempty"`
States map[string]int `json:"states,omitempty"`