Skip to content

Commit 7f7d84b

Browse files
fuufenmergify[bot]
andauthored
fix: match cache restore-keys in creation reverse order (#2153)
* Match cache restore-keys in creation reverse order * Match full prefix when selecting cache --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 15bb54f commit 7f7d84b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

pkg/artifactcache/handler.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"net/http"
1010
"os"
1111
"path/filepath"
12+
"regexp"
1213
"strconv"
1314
"strings"
1415
"sync/atomic"
@@ -386,7 +387,12 @@ func (h *Handler) findCache(db *bolthold.Store, keys []string, version string) (
386387

387388
for _, prefix := range keys[1:] {
388389
found := false
389-
if err := db.ForEach(bolthold.Where("Key").Ge(prefix).And("Version").Eq(version).SortBy("Key"), func(v *Cache) error {
390+
prefixPattern := fmt.Sprintf("^%s", regexp.QuoteMeta(prefix))
391+
re, err := regexp.Compile(prefixPattern)
392+
if err != nil {
393+
continue
394+
}
395+
if err := db.ForEach(bolthold.Where("Key").RegExp(re).And("Version").Eq(version).SortBy("CreatedAt").Reverse(), func(v *Cache) error {
390396
if !strings.HasPrefix(v.Key, prefix) {
391397
return stop
392398
}

0 commit comments

Comments
 (0)