This commit is contained in:
xing 2023-11-07 15:36:00 +08:00
parent 928a608878
commit f6a5cf4255

12
cache/map.go vendored
View File

@ -151,22 +151,18 @@ func (m *MapCache[K, V]) getBatchToMap(e Expend[K, V]) func(c context.Context, k
var needIndex = make(map[K]int) var needIndex = make(map[K]int)
var err error var err error
mm, err := e.Gets(ctx, key) mm, err := e.Gets(ctx, key)
if err != nil { if err != nil || len(key) == len(mm) {
return nil, err return mm, err
} }
res = mm
var flushKeys []K var flushKeys []K
for i, k := range key { for i, k := range key {
v, ok := mm[k] _, ok := mm[k]
if !ok { if !ok {
flushKeys = append(flushKeys, k) flushKeys = append(flushKeys, k)
needIndex[k] = i needIndex[k] = i
} else {
res[k] = v
} }
} }
if len(needIndex) < 1 {
return res, nil
}
call := func() { call := func() {
m.mux.Lock() m.mux.Lock()