mirror of
https://github.com/rancher/steve.git
synced 2025-04-27 19:05:09 +00:00
Skip key generation if cache disabled (#170)
This commit is contained in:
parent
dc4a394d55
commit
d42a5bc545
@ -175,18 +175,22 @@ func (s *Store) List(apiOp *types.APIRequest, schema *types.APISchema) (types.AP
|
|||||||
|
|
||||||
opts := listprocessor.ParseQuery(apiOp)
|
opts := listprocessor.ParseQuery(apiOp)
|
||||||
|
|
||||||
key, err := s.getCacheKey(apiOp, opts)
|
|
||||||
if err != nil {
|
|
||||||
return result, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var list []unstructured.Unstructured
|
var list []unstructured.Unstructured
|
||||||
if key.revision != "" && s.listCache != nil {
|
var key cacheKey
|
||||||
cachedList, ok := s.listCache.Get(key)
|
if s.listCache != nil {
|
||||||
if ok {
|
key, err = s.getCacheKey(apiOp, opts)
|
||||||
logrus.Tracef("found cached list for query %s?%s", apiOp.Request.URL.Path, apiOp.Request.URL.RawQuery)
|
if err != nil {
|
||||||
list = cachedList.(*unstructured.UnstructuredList).Items
|
return result, err
|
||||||
result.Continue = cachedList.(*unstructured.UnstructuredList).GetContinue()
|
}
|
||||||
|
|
||||||
|
if key.revision != "" {
|
||||||
|
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()
|
||||||
|
result.Revision = key.revision
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if list == nil { // did not look in cache or was not found in cache
|
if list == nil { // did not look in cache or was not found in cache
|
||||||
@ -202,7 +206,7 @@ func (s *Store) List(apiOp *types.APIRequest, schema *types.APISchema) (types.AP
|
|||||||
return result, lister.Err()
|
return result, lister.Err()
|
||||||
}
|
}
|
||||||
list = listprocessor.SortList(list, opts.Sort)
|
list = listprocessor.SortList(list, opts.Sort)
|
||||||
key.revision = lister.Revision()
|
result.Revision = lister.Revision()
|
||||||
listToCache := &unstructured.UnstructuredList{
|
listToCache := &unstructured.UnstructuredList{
|
||||||
Items: list,
|
Items: list,
|
||||||
}
|
}
|
||||||
@ -212,6 +216,7 @@ func (s *Store) List(apiOp *types.APIRequest, schema *types.APISchema) (types.AP
|
|||||||
listToCache.SetContinue(c)
|
listToCache.SetContinue(c)
|
||||||
}
|
}
|
||||||
if s.listCache != nil {
|
if s.listCache != nil {
|
||||||
|
key.revision = result.Revision
|
||||||
s.listCache.Add(key, listToCache, 30*time.Minute)
|
s.listCache.Add(key, listToCache, 30*time.Minute)
|
||||||
}
|
}
|
||||||
result.Continue = lister.Continue()
|
result.Continue = lister.Continue()
|
||||||
@ -224,7 +229,6 @@ func (s *Store) List(apiOp *types.APIRequest, schema *types.APISchema) (types.AP
|
|||||||
result.Objects = append(result.Objects, toAPI(schema, item, nil))
|
result.Objects = append(result.Objects, toAPI(schema, item, nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
result.Revision = key.revision
|
|
||||||
result.Pages = pages
|
result.Pages = pages
|
||||||
return result, lister.Err()
|
return result, lister.Err()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user