@@ -492,21 +492,22 @@ func (s sortableStoreElements) Swap(i, j int) {
492
492
493
493
// WaitUntilFreshAndList returns list of pointers to `storeElement` objects along
494
494
// with their ResourceVersion and the name of the index, if any, that was used.
495
- func (w * watchCache ) WaitUntilFreshAndList (ctx context.Context , resourceVersion uint64 , matchValues []storage.MatchValue ) ([]interface {}, uint64 , string , error ) {
496
- var err error
495
+ func (w * watchCache ) WaitUntilFreshAndList (ctx context.Context , resourceVersion uint64 , matchValues []storage.MatchValue ) (result []interface {}, rv uint64 , index string , err error ) {
497
496
if utilfeature .DefaultFeatureGate .Enabled (features .ConsistentListFromCache ) && w .notFresh (resourceVersion ) {
498
497
w .waitingUntilFresh .Add ()
499
498
err = w .waitUntilFreshAndBlock (ctx , resourceVersion )
500
499
w .waitingUntilFresh .Remove ()
501
500
} else {
502
501
err = w .waitUntilFreshAndBlock (ctx , resourceVersion )
503
502
}
503
+
504
+ defer func () { sort .Sort (sortableStoreElements (result )) }()
504
505
defer w .RUnlock ()
505
506
if err != nil {
506
- return nil , 0 , "" , err
507
+ return result , rv , index , err
507
508
}
508
509
509
- result , rv , index , err : = func () ([]interface {}, uint64 , string , error ) {
510
+ result , rv , index , err = func () ([]interface {}, uint64 , string , error ) {
510
511
// This isn't the place where we do "final filtering" - only some "prefiltering" is happening here. So the only
511
512
// requirement here is to NOT miss anything that should be returned. We can return as many non-matching items as we
512
513
// want - they will be filtered out later. The fact that we return less things is only further performance improvement.
@@ -519,7 +520,6 @@ func (w *watchCache) WaitUntilFreshAndList(ctx context.Context, resourceVersion
519
520
return w .store .List (), w .resourceVersion , "" , nil
520
521
}()
521
522
522
- sort .Sort (sortableStoreElements (result ))
523
523
return result , rv , index , err
524
524
}
525
525
0 commit comments