1
0
mirror of https://github.com/rancher/steve.git synced 2025-09-16 23:39:16 +00:00

Cleanup counts

This commit is contained in:
Darren Shepherd
2019-08-16 11:40:42 -07:00
parent b059dcca00
commit 5142b5c386
4 changed files with 64 additions and 5 deletions

View File

@@ -6,6 +6,8 @@ import (
"sync"
"time"
"github.com/rancher/naok/pkg/attributes"
"github.com/rancher/naok/pkg/accesscontrol"
"github.com/rancher/norman/pkg/store/empty"
"github.com/rancher/norman/pkg/types"
@@ -79,6 +81,8 @@ func (s *Store) Watch(apiOp *types.APIRequest, schema *types.Schema, w types.Wat
child := make(chan Count)
for name, countItem := range c.Counts {
wg.Add(1)
name := name
countItem := countItem
go func() {
s.watchItem(apiOp.WithContext(ctx), name, countItem, cancel, child)
wg.Done()
@@ -121,9 +125,10 @@ func (s *Store) watchItem(apiOp *types.APIRequest, schemaID string, start ItemCo
if schema == nil || schema.Store == nil || apiOp.AccessControl.CanWatch(apiOp, schema) != nil {
return
}
defer cancel()
logrus.Debugf("watching %s for count", schemaID)
defer logrus.Debugf("close watching %s for count", schemaID)
w, err := schema.Store.Watch(apiOp, schema, types.WatchRequest{Revision: start.Revision})
if err != nil {
logrus.Errorf("failed to watch %s for counts: %v", schema.ID, err)
@@ -171,6 +176,14 @@ func (s *Store) getCount(apiOp *types.APIRequest, timeout time.Duration, ignoreS
continue
}
if attributes.PreferredVersion(schema) != "" {
continue
}
if attributes.PreferredGroup(schema) != "" {
continue
}
if ignoreSlow && slow[schema.ID] {
continue
}