mirror of
https://github.com/rancher/steve.git
synced 2025-09-18 16:39:07 +00:00
Only send counts every second if there is a change
This commit is contained in:
@@ -118,6 +118,14 @@ func (s *Store) Watch(apiOp *types.APIRequest, schema *types.APISchema, w types.
|
||||
countLock sync.Mutex
|
||||
)
|
||||
|
||||
go func() {
|
||||
<-apiOp.Context().Done()
|
||||
countLock.Lock()
|
||||
close(result)
|
||||
result = nil
|
||||
countLock.Unlock()
|
||||
}()
|
||||
|
||||
counts = s.getCount(apiOp).Counts
|
||||
for id := range counts {
|
||||
schema := apiOp.Schemas.LookupSchema(id)
|
||||
@@ -128,14 +136,6 @@ func (s *Store) Watch(apiOp *types.APIRequest, schema *types.APISchema, w types.
|
||||
gvrToSchema[attributes.GVR(schema)] = schema
|
||||
}
|
||||
|
||||
go func() {
|
||||
<-apiOp.Context().Done()
|
||||
countLock.Lock()
|
||||
close(result)
|
||||
result = nil
|
||||
countLock.Unlock()
|
||||
}()
|
||||
|
||||
onChange := func(add bool, gvr schema2.GroupVersionResource, _ string, obj, oldObj runtime.Object) error {
|
||||
countLock.Lock()
|
||||
defer countLock.Unlock()
|
||||
@@ -205,7 +205,7 @@ func (s *Store) Watch(apiOp *types.APIRequest, schema *types.APISchema, w types.
|
||||
return onChange(false, gvr, key, obj, nil)
|
||||
})
|
||||
|
||||
return result, nil
|
||||
return buffer(result), nil
|
||||
}
|
||||
|
||||
func (s *Store) schemasToWatch(apiOp *types.APIRequest) (result []*types.APISchema) {
|
||||
|
Reference in New Issue
Block a user