From cd4787991df2caabaca1a99c56a46ed53a0d9978 Mon Sep 17 00:00:00 2001 From: xing Date: Sat, 28 Oct 2023 18:37:00 +0800 Subject: [PATCH] optimize optimize...... --- cache/map.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/cache/map.go b/cache/map.go index 865be4c..9ee8e97 100644 --- a/cache/map.go +++ b/cache/map.go @@ -164,17 +164,15 @@ func (m *MapCache[K, V]) GetCacheBatch(c context.Context, key []K, timeout time. err = er return } - for k, v := range r { - m.Set(c, k, v) - if i, ok := needIndex[k]; ok { - res[i] = v - delete(needIndex, k) - } - } for k, i := range needIndex { - v, ok := m.Get(c, k) + v, ok := r[k] if ok { res[i] = v + } else { + v, ok = m.Get(c, k) + if ok { + res[i] = v + } } } }