mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 06:27:05 +00:00
Fix lack of sorting of list results in watchcache
This commit is contained in:
parent
da8d197a72
commit
aaaee155dd
@ -463,6 +463,20 @@ func (w *watchCache) waitUntilFreshAndBlock(ctx context.Context, resourceVersion
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type sortableStoreElements []interface{}
|
||||||
|
|
||||||
|
func (s sortableStoreElements) Len() int {
|
||||||
|
return len(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s sortableStoreElements) Less(i, j int) bool {
|
||||||
|
return s[i].(*storeElement).Key < s[j].(*storeElement).Key
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s sortableStoreElements) Swap(i, j int) {
|
||||||
|
s[i], s[j] = s[j], s[i]
|
||||||
|
}
|
||||||
|
|
||||||
// WaitUntilFreshAndList returns list of pointers to `storeElement` objects along
|
// WaitUntilFreshAndList returns list of pointers to `storeElement` objects along
|
||||||
// with their ResourceVersion and the name of the index, if any, that was used.
|
// with their ResourceVersion and the name of the index, if any, that was used.
|
||||||
func (w *watchCache) WaitUntilFreshAndList(ctx context.Context, resourceVersion uint64, matchValues []storage.MatchValue) ([]interface{}, uint64, string, error) {
|
func (w *watchCache) WaitUntilFreshAndList(ctx context.Context, resourceVersion uint64, matchValues []storage.MatchValue) ([]interface{}, uint64, string, error) {
|
||||||
@ -472,16 +486,21 @@ func (w *watchCache) WaitUntilFreshAndList(ctx context.Context, resourceVersion
|
|||||||
return nil, 0, "", err
|
return nil, 0, "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
// This isn't the place where we do "final filtering" - only some "prefiltering" is happening here. So the only
|
result, rv, index, err := func() ([]interface{}, uint64, string, error) {
|
||||||
// requirement here is to NOT miss anything that should be returned. We can return as many non-matching items as we
|
// This isn't the place where we do "final filtering" - only some "prefiltering" is happening here. So the only
|
||||||
// want - they will be filtered out later. The fact that we return less things is only further performance improvement.
|
// requirement here is to NOT miss anything that should be returned. We can return as many non-matching items as we
|
||||||
// TODO: if multiple indexes match, return the one with the fewest items, so as to do as much filtering as possible.
|
// want - they will be filtered out later. The fact that we return less things is only further performance improvement.
|
||||||
for _, matchValue := range matchValues {
|
// TODO: if multiple indexes match, return the one with the fewest items, so as to do as much filtering as possible.
|
||||||
if result, err := w.store.ByIndex(matchValue.IndexName, matchValue.Value); err == nil {
|
for _, matchValue := range matchValues {
|
||||||
return result, w.resourceVersion, matchValue.IndexName, nil
|
if result, err := w.store.ByIndex(matchValue.IndexName, matchValue.Value); err == nil {
|
||||||
|
return result, w.resourceVersion, matchValue.IndexName, nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
return w.store.List(), w.resourceVersion, "", nil
|
||||||
return w.store.List(), w.resourceVersion, "", nil
|
}()
|
||||||
|
|
||||||
|
sort.Sort(sortableStoreElements(result))
|
||||||
|
return result, rv, index, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// WaitUntilFreshAndGet returns a pointers to <storeElement> object.
|
// WaitUntilFreshAndGet returns a pointers to <storeElement> object.
|
||||||
|
Loading…
Reference in New Issue
Block a user