mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-10-05 19:30:59 +00:00
chore: cache: move findCacheWithIsolationKeyFallback out of handler.find
This commit is contained in:
parent
c48accfb51
commit
5f0b036e34
2 changed files with 16 additions and 9 deletions
|
@ -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{}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue