From 5f0b036e34966fc3eafa46e2df94cbf1ef58e2fc Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Fri, 5 Sep 2025 17:21:53 +0200 Subject: [PATCH] chore: cache: move findCacheWithIsolationKeyFallback out of handler.find --- act/artifactcache/caches.go | 15 +++++++++++++++ act/artifactcache/handler.go | 10 +--------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/act/artifactcache/caches.go b/act/artifactcache/caches.go index 16b3204d..6d499c8a 100644 --- a/act/artifactcache/caches.go +++ b/act/artifactcache/caches.go @@ -90,6 +90,21 @@ func (c *cachesImpl) openDB() (*bolthold.Store, error) { return db, nil } +var findCacheWithIsolationKeyFallback = func(db *bolthold.Store, repo string, keys []string, version, writeIsolationKey string) (*Cache, error) { + cache, err := findCache(db, repo, keys, version, writeIsolationKey) + if err != nil { + return nil, err + } + // If read was scoped to WriteIsolationKey and didn't find anything, we can fallback to the non-isolated cache read + if cache == nil && writeIsolationKey != "" { + cache, err = findCache(db, repo, keys, version, "") + if err != nil { + return nil, err + } + } + return cache, nil +} + // if not found, return (nil, nil) instead of an error. func findCache(db *bolthold.Store, repo string, keys []string, version, writeIsolationKey string) (*Cache, error) { cache := &Cache{} diff --git a/act/artifactcache/handler.go b/act/artifactcache/handler.go index d8a56e19..0b574397 100644 --- a/act/artifactcache/handler.go +++ b/act/artifactcache/handler.go @@ -177,19 +177,11 @@ func (h *handler) find(w http.ResponseWriter, r *http.Request, params httprouter } defer db.Close() - cache, err := findCache(db, repo, keys, version, rundata.WriteIsolationKey) + cache, err := findCacheWithIsolationKeyFallback(db, repo, keys, version, rundata.WriteIsolationKey) if err != nil { h.responseFatalJSON(w, r, err) return } - // If read was scoped to WriteIsolationKey and didn't find anything, we can fallback to the non-isolated cache read - if cache == nil && rundata.WriteIsolationKey != "" { - cache, err = findCache(db, repo, keys, version, "") - if err != nil { - h.responseFatalJSON(w, r, err) - return - } - } if cache == nil { h.responseJSON(w, r, 204) return