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>
This commit is contained in:
parent
15bb54f14e
commit
7f7d84b10f
|
@ -9,6 +9,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
@ -386,7 +387,12 @@ func (h *Handler) findCache(db *bolthold.Store, keys []string, version string) (
|
||||||
|
|
||||||
for _, prefix := range keys[1:] {
|
for _, prefix := range keys[1:] {
|
||||||
found := false
|
found := false
|
||||||
if err := db.ForEach(bolthold.Where("Key").Ge(prefix).And("Version").Eq(version).SortBy("Key"), func(v *Cache) error {
|
prefixPattern := fmt.Sprintf("^%s", regexp.QuoteMeta(prefix))
|
||||||
|
re, err := regexp.Compile(prefixPattern)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err := db.ForEach(bolthold.Where("Key").RegExp(re).And("Version").Eq(version).SortBy("CreatedAt").Reverse(), func(v *Cache) error {
|
||||||
if !strings.HasPrefix(v.Key, prefix) {
|
if !strings.HasPrefix(v.Key, prefix) {
|
||||||
return stop
|
return stop
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue