feat: cache optimize

pull/1329/head
withchao 2 years ago
parent 0ea06a3880
commit a736022c8e

@ -17,6 +17,8 @@ package third
import ( import (
"context" "context"
"fmt" "fmt"
"github.com/OpenIMSDK/tools/errs"
"github.com/OpenIMSDK/tools/mw/specialerror"
"net/url" "net/url"
"time" "time"
@ -78,6 +80,12 @@ func Start(client discoveryregistry.SvcDiscoveryRegistry, server *grpc.Server) e
if err != nil { if err != nil {
return err return err
} }
specialerror.AddErrHandler(func(err error) errs.CodeError {
if o.IsNotFound(err) {
return errs.ErrRecordNotFound
}
return nil
})
third.RegisterThirdServer(server, &thirdServer{ third.RegisterThirdServer(server, &thirdServer{
apiURL: apiURL, apiURL: apiURL,
thirdDatabase: controller.NewThirdDatabase(cache.NewMsgCacheModel(rdb), db), thirdDatabase: controller.NewThirdDatabase(cache.NewMsgCacheModel(rdb), db),

@ -18,6 +18,7 @@ import (
"context" "context"
"encoding/json" "encoding/json"
"errors" "errors"
"github.com/OpenIMSDK/tools/mw/specialerror"
"time" "time"
"github.com/dtm-labs/rockscache" "github.com/dtm-labs/rockscache"
@ -209,7 +210,7 @@ func batchGetCache2[T any, K comparable](
return fns(ctx, key) return fns(ctx, key)
}) })
if err != nil { if err != nil {
if errs.ErrRecordNotFound.Is(err) { if errs.ErrRecordNotFound.Is(specialerror.ErrCode(errs.Unwrap(err))) {
continue continue
} }
return nil, err return nil, err

Loading…
Cancel
Save