Filter List in Storage level to avoid additional copies.
This commit is contained in:
@@ -150,6 +150,7 @@ func (e *Etcd) List(ctx api.Context, label labels.Selector, field fields.Selecto
|
||||
func (e *Etcd) ListPredicate(ctx api.Context, m generic.Matcher) (runtime.Object, error) {
|
||||
list := e.NewListFunc()
|
||||
trace := util.NewTrace("List " + reflect.TypeOf(list).String())
|
||||
filterFunc := e.filterAndDecorateFunction(m)
|
||||
defer trace.LogIfLong(600 * time.Millisecond)
|
||||
if name, ok := m.MatchesSingle(); ok {
|
||||
trace.Step("About to read single object")
|
||||
@@ -157,21 +158,20 @@ func (e *Etcd) ListPredicate(ctx api.Context, m generic.Matcher) (runtime.Object
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
err = e.Storage.GetToList(key, list)
|
||||
err = e.Storage.GetToList(key, filterFunc, list)
|
||||
trace.Step("Object extracted")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
trace.Step("About to list directory")
|
||||
err := e.Storage.List(e.KeyRootFunc(ctx), list)
|
||||
err := e.Storage.List(e.KeyRootFunc(ctx), filterFunc, list)
|
||||
trace.Step("List extracted")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
defer trace.Step("List filtered")
|
||||
return generic.FilterList(list, m, generic.DecoratorFunc(e.Decorator))
|
||||
return list, nil
|
||||
}
|
||||
|
||||
// Create inserts a new item according to the unique key from the object.
|
||||
@@ -449,8 +449,21 @@ func (e *Etcd) WatchPredicate(ctx api.Context, m generic.Matcher, resourceVersio
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
filterFunc := e.filterAndDecorateFunction(m)
|
||||
|
||||
filterFunc := func(obj runtime.Object) bool {
|
||||
if name, ok := m.MatchesSingle(); ok {
|
||||
key, err := e.KeyFunc(ctx, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return e.Storage.Watch(key, version, filterFunc)
|
||||
}
|
||||
|
||||
return e.Storage.WatchList(e.KeyRootFunc(ctx), version, filterFunc)
|
||||
}
|
||||
|
||||
func (e *Etcd) filterAndDecorateFunction(m generic.Matcher) func(runtime.Object) bool {
|
||||
return func(obj runtime.Object) bool {
|
||||
matches, err := m.Matches(obj)
|
||||
if err != nil {
|
||||
glog.Errorf("unable to match watch: %v", err)
|
||||
@@ -464,16 +477,6 @@ func (e *Etcd) WatchPredicate(ctx api.Context, m generic.Matcher, resourceVersio
|
||||
}
|
||||
return matches
|
||||
}
|
||||
|
||||
if name, ok := m.MatchesSingle(); ok {
|
||||
key, err := e.KeyFunc(ctx, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return e.Storage.Watch(key, version, filterFunc)
|
||||
}
|
||||
|
||||
return e.Storage.WatchList(e.KeyRootFunc(ctx), version, filterFunc)
|
||||
}
|
||||
|
||||
// calculateTTL is a helper for retrieving the updated TTL for an object or returning an error
|
||||
|
||||
Reference in New Issue
Block a user