From 0462af3b9ac29432b1bcf73c8985a69b7e449897 Mon Sep 17 00:00:00 2001 From: Ricardo Weir Date: Tue, 20 Feb 2024 17:10:55 -0700 Subject: [PATCH] Skip key generation if cache disabled --- pkg/stores/partition/store.go | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/pkg/stores/partition/store.go b/pkg/stores/partition/store.go index e51ab374e..8442f3f90 100644 --- a/pkg/stores/partition/store.go +++ b/pkg/stores/partition/store.go @@ -175,18 +175,21 @@ func (s *Store) List(apiOp *types.APIRequest, schema *types.APISchema) (types.AP opts := listprocessor.ParseQuery(apiOp) - key, err := s.getCacheKey(apiOp, opts) - if err != nil { - return result, err - } - var list []unstructured.Unstructured - if key.revision != "" && s.listCache != nil { - cachedList, ok := s.listCache.Get(key) - if ok { - logrus.Tracef("found cached list for query %s?%s", apiOp.Request.URL.Path, apiOp.Request.URL.RawQuery) - list = cachedList.(*unstructured.UnstructuredList).Items - result.Continue = cachedList.(*unstructured.UnstructuredList).GetContinue() + var key cacheKey + if s.listCache != nil { + key, err = s.getCacheKey(apiOp, opts) + if err != nil { + return result, err + } + + if key.revision != "" && s.listCache != nil { + cachedList, ok := s.listCache.Get(key) + if ok { + logrus.Tracef("found cached list for query %s?%s", apiOp.Request.URL.Path, apiOp.Request.URL.RawQuery) + list = cachedList.(*unstructured.UnstructuredList).Items + result.Continue = cachedList.(*unstructured.UnstructuredList).GetContinue() + } } } if list == nil { // did not look in cache or was not found in cache @@ -202,7 +205,7 @@ func (s *Store) List(apiOp *types.APIRequest, schema *types.APISchema) (types.AP return result, lister.Err() } list = listprocessor.SortList(list, opts.Sort) - key.revision = lister.Revision() + result.Revision = lister.Revision() listToCache := &unstructured.UnstructuredList{ Items: list, } @@ -212,6 +215,7 @@ func (s *Store) List(apiOp *types.APIRequest, schema *types.APISchema) (types.AP listToCache.SetContinue(c) } if s.listCache != nil { + key.revision = result.Revision s.listCache.Add(key, listToCache, 30*time.Minute) } result.Continue = lister.Continue() @@ -224,7 +228,6 @@ func (s *Store) List(apiOp *types.APIRequest, schema *types.APISchema) (types.AP result.Objects = append(result.Objects, toAPI(schema, &item, nil)) } - result.Revision = key.revision result.Pages = pages return result, lister.Err() }