From a736022c8e2b21f6a4c4a8c83ef3737a3866f679 Mon Sep 17 00:00:00 2001 From: withchao <993506633@qq.com> Date: Thu, 2 Nov 2023 15:54:16 +0800 Subject: [PATCH] feat: cache optimize --- internal/rpc/third/third.go | 8 ++++++++ pkg/common/db/cache/meta_cache.go | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/internal/rpc/third/third.go b/internal/rpc/third/third.go index a350c6915..580a6085e 100644 --- a/internal/rpc/third/third.go +++ b/internal/rpc/third/third.go @@ -17,6 +17,8 @@ package third import ( "context" "fmt" + "github.com/OpenIMSDK/tools/errs" + "github.com/OpenIMSDK/tools/mw/specialerror" "net/url" "time" @@ -78,6 +80,12 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e if err != nil { return err } + specialerror.AddErrHandler(func(err error) errs.CodeError { + if o.IsNotFound(err) { + return errs.ErrRecordNotFound + } + return nil + }) third.RegisterThirdServer(server, &thirdServer{ apiURL: apiURL, thirdDatabase: controller.NewThirdDatabase(cache.NewMsgCacheModel(rdb), db), diff --git a/pkg/common/db/cache/meta_cache.go b/pkg/common/db/cache/meta_cache.go index f27e564c1..45888ed8f 100644 --- a/pkg/common/db/cache/meta_cache.go +++ b/pkg/common/db/cache/meta_cache.go @@ -18,6 +18,7 @@ import ( "context" "encoding/json" "errors" + "github.com/OpenIMSDK/tools/mw/specialerror" "time" "github.com/dtm-labs/rockscache" @@ -209,7 +210,7 @@ func batchGetCache2[T any, K comparable]( return fns(ctx, key) }) if err != nil { - if errs.ErrRecordNotFound.Is(err) { + if errs.ErrRecordNotFound.Is(specialerror.ErrCode(errs.Unwrap(err))) { continue } return nil, err