From f6a5cf4255dd747876a1b3f671927132f478f9a9 Mon Sep 17 00:00:00 2001 From: xing Date: Tue, 7 Nov 2023 15:36:00 +0800 Subject: [PATCH] optimize --- cache/map.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/cache/map.go b/cache/map.go index 6322cd2..933f1b6 100644 --- a/cache/map.go +++ b/cache/map.go @@ -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 err error mm, err := e.Gets(ctx, key) - if err != nil { - return nil, err + if err != nil || len(key) == len(mm) { + return mm, err } + res = mm var flushKeys []K for i, k := range key { - v, ok := mm[k] + _, ok := mm[k] if !ok { flushKeys = append(flushKeys, k) needIndex[k] = i - } else { - res[k] = v } } - if len(needIndex) < 1 { - return res, nil - } call := func() { m.mux.Lock()