From b06424490795c0029d5449a12381c37a766d20ea Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Thu, 14 Jul 2022 12:08:28 +0800 Subject: [PATCH] rocks cache --- cmd/open_im_demo/main.go | 1 + docker-compose.yaml | 13 + go.mod | 6 +- go.sum | 16 +- internal/demo/register/onboarding_process.go | 24 + internal/demo/register/set_password.go | 13 +- internal/rpc/cache/cache.go | 254 +--- internal/rpc/friend/{firend.go => friend.go} | 127 +- internal/rpc/group/group.go | 326 +++-- internal/rpc/organization/organization.go | 4 +- internal/rpc/user/user.go | 46 +- pkg/common/db/RedisModel.go | 88 +- pkg/common/db/model.go | 9 +- pkg/common/db/mysql.go | 108 +- .../im_mysql_model/conversation_model.go | 91 +- .../mysql_model/im_mysql_model/demo_model.go | 21 +- .../mysql_model/im_mysql_model/file_model.go | 15 +- .../im_mysql_model/friend_model.go | 50 +- .../im_mysql_model/friend_request_model.go | 38 +- .../im_mysql_model/group_member_model.go | 125 +- .../mysql_model/im_mysql_model/group_model.go | 101 +- .../im_mysql_model/group_request_model.go | 44 +- .../mysql_model/im_mysql_model/message_cms.go | 20 +- .../im_mysql_model/organization_model.go | 178 +-- .../im_mysql_model/statistics_model.go | 117 +- .../im_mysql_model/user_black_list_model.go | 32 +- .../mysql_model/im_mysql_model/user_model.go | 145 +-- .../im_mysql_msg_model/chat_log_model.go | 6 +- .../im_mysql_msg_model/hash_code.go | 20 - pkg/common/db/rocks_cache/rocks_cache.go | 248 ++++ pkg/common/utils/utils.go | 3 +- pkg/proto/cache/cache.pb.go | 1074 ++++------------- pkg/proto/cache/cache.proto | 95 +- test/redis/cmd/main.go | 94 -- 34 files changed, 1104 insertions(+), 2448 deletions(-) rename internal/rpc/friend/{firend.go => friend.go} (86%) create mode 100644 pkg/common/db/rocks_cache/rocks_cache.go delete mode 100644 test/redis/cmd/main.go diff --git a/cmd/open_im_demo/main.go b/cmd/open_im_demo/main.go index 71d3e114c..b73fe7676 100644 --- a/cmd/open_im_demo/main.go +++ b/cmd/open_im_demo/main.go @@ -50,6 +50,7 @@ func main() { } address = config.Config.CmsApi.ListenIP + ":" + strconv.Itoa(*ginPort) fmt.Println("start demo api server address: ", address) + go register.OnboardingProcessRoutine() err := r.Run(address) if err != nil { log.Error("", "run failed ", *ginPort, err.Error()) diff --git a/docker-compose.yaml b/docker-compose.yaml index cd3fb1294..e22368f87 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -113,6 +113,18 @@ services: restart: always command: minio server /data --console-address ':9090' + dtm: + image: yedf/dtm + ports: + - 36789:36789 + - 36790:36790 + environment: + STORE_DRIVER: mysql + STORE_HOST: localhost + STORE_USER: root + STORE_PASSWORD: '' + STORE_PORT: 3306 + open_im_server: image: openim/open_im_server:v2.2.0 container_name: open_im_server @@ -129,6 +141,7 @@ services: - redis - etcd - minio + - dtm network_mode: "host" logging: driver: json-file diff --git a/go.mod b/go.mod index 921b67a0a..64bdb5476 100644 --- a/go.mod +++ b/go.mod @@ -19,20 +19,16 @@ require ( github.com/go-openapi/swag v0.21.1 // indirect github.com/go-playground/validator/v10 v10.11.0 github.com/go-redis/redis/v8 v8.11.5 - github.com/go-sql-driver/mysql v1.6.0 // indirect github.com/gogo/protobuf v1.3.2 github.com/golang-jwt/jwt/v4 v4.1.0 github.com/golang/protobuf v1.5.2 github.com/gorilla/websocket v1.4.2 github.com/jinzhu/copier v0.3.4 github.com/jinzhu/gorm v1.9.16 - github.com/jinzhu/now v1.1.3 // indirect github.com/jonboulle/clockwork v0.2.2 // indirect github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible github.com/lestrrat-go/strftime v1.0.4 // indirect - github.com/lib/pq v1.2.0 // indirect github.com/lithammer/shortuuid v3.0.0+incompatible - github.com/mattn/go-sqlite3 v1.14.6 // indirect github.com/minio/minio-go/v7 v7.0.22 github.com/mitchellh/mapstructure v1.4.2 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 @@ -64,6 +60,8 @@ require ( gopkg.in/ini.v1 v1.66.2 // indirect gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 gopkg.in/yaml.v3 v3.0.1 + gorm.io/driver/mysql v1.3.5 + gorm.io/gorm v1.23.8 ) replace github.com/Shopify/sarama => github.com/Shopify/sarama v1.29.0 diff --git a/go.sum b/go.sum index afe45d430..78606c424 100644 --- a/go.sum +++ b/go.sum @@ -84,7 +84,6 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd h1:83Wprp6ROGeiHFAP8WJdI2RoxALQYgdllERc3N5N2DM= github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= @@ -112,7 +111,6 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20210217033140-668b12f5399d/go.m github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.mod h1:hliV/p42l8fGbc6Y9bQ70uLwIvmJyVE5k4iMKlh8wCQ= github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= -github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DPaBjB8zlTR87/ElzFsnQfuHnVUVqpZZIcV5Y= github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0= github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= @@ -183,7 +181,6 @@ github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang-jwt/jwt/v4 v4.1.0 h1:XUgk2Ex5veyVFVeLm0xhusUTQybEbexJXrvPNOKkSY0= github.com/golang-jwt/jwt/v4 v4.1.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg= -github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY= github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -256,8 +253,9 @@ github.com/jinzhu/gorm v1.9.16/go.mod h1:G3LB3wezTOWM2ITLzPxEXgSkOXAntiLHS7UdBef github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= -github.com/jinzhu/now v1.1.3 h1:PlHq1bSCSZL9K0wUhbm2pGLoTWs2GwVhsP6emvGV/ZI= -github.com/jinzhu/now v1.1.3/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= +github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/jonboulle/clockwork v0.2.2 h1:UOGuzwb1PwsrDAObMuhUnj0p5ULPj8V/xJ7Kx9qUBdQ= @@ -304,8 +302,6 @@ github.com/lestrrat-go/file-rotatelogs v2.4.0+incompatible/go.mod h1:ZQnN8lSECae github.com/lestrrat-go/strftime v1.0.4 h1:T1Rb9EPkAhgxKqbcMIPguPq8glqXTA1koF8n9BHElA8= github.com/lestrrat-go/strftime v1.0.4/go.mod h1:E1nN3pCbtMSu1yjSVeyuRFVm/U0xoR76fd03sz+Qz4g= github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= -github.com/lib/pq v1.2.0 h1:LXpIM/LZ5xGFhOpXAQUIMM1HdyqzVYM13zNdjCEEcA0= -github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= github.com/lithammer/shortuuid v3.0.0+incompatible h1:NcD0xWW/MZYXEHa6ITy6kaXN5nwm/V115vj2YXfhS0w= github.com/lithammer/shortuuid v3.0.0+incompatible/go.mod h1:FR74pbAuElzOUuenUHTK2Tciko1/vKuIKS9dSkDrA4w= github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc= @@ -317,8 +313,6 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus= -github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRUbg= -github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/minio/md5-simd v1.1.0 h1:QPfiOqlZH+Cj9teu0t9b1nTBfPbyTl16Of5MeuShdK4= github.com/minio/md5-simd v1.1.0/go.mod h1:XpBqgZULrMYD3R+M28PcmP0CkI7PEMzB3U77ZrKZ0Gw= @@ -718,6 +712,10 @@ gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gorm.io/driver/mysql v1.3.5 h1:iWBTVW/8Ij5AG4e0G/zqzaJblYkBI1VIL1LG2HUGsvY= +gorm.io/driver/mysql v1.3.5/go.mod h1:sSIebwZAVPiT+27jK9HIwvsqOGKx3YMPmrA3mBJR10c= +gorm.io/gorm v1.23.8 h1:h8sGJ+biDgBA1AD1Ha9gFCx7h8npU7AsLdlkX0n2TpE= +gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= diff --git a/internal/demo/register/onboarding_process.go b/internal/demo/register/onboarding_process.go index 38a0d44e9..9100bab89 100644 --- a/internal/demo/register/onboarding_process.go +++ b/internal/demo/register/onboarding_process.go @@ -21,6 +21,30 @@ import ( "time" ) +type OnboardingProcessReq struct { + OperationID string + UserID string + NickName string + FaceURL string + PhoneNumber string + Email string +} + +var Ch chan OnboardingProcessReq + +func init() { + Ch = make(chan OnboardingProcessReq, 1000) +} + +func OnboardingProcessRoutine() { + for { + req := <-Ch + go func() { + onboardingProcess(req.OperationID, req.UserID, req.NickName, req.FaceURL, req.PhoneNumber, req.Email) + }() + } +} + func onboardingProcess(operationID, userID, userName, faceURL, phoneNumber, email string) { log.NewInfo(operationID, utils.GetSelfFuncName(), userName, userID, faceURL) if err := createOrganizationUser(operationID, userID, userName, phoneNumber, email); err != nil { diff --git a/internal/demo/register/set_password.go b/internal/demo/register/set_password.go index c3aab18d2..69a094204 100644 --- a/internal/demo/register/set_password.go +++ b/internal/demo/register/set_password.go @@ -108,7 +108,18 @@ func SetPassword(c *gin.Context) { log.Info(params.OperationID, "end setPassword", account, params.Password) // demo onboarding if params.UserID == "" { - onboardingProcess(params.OperationID, userID, params.Nickname, params.FaceURL, params.AreaCode+params.PhoneNumber, params.Email) + select { + case Ch <- OnboardingProcessReq{ + OperationID: params.OperationID, + UserID: params.UserID, + NickName: params.Nickname, + FaceURL: params.FaceURL, + PhoneNumber: params.AreaCode + params.PhoneNumber, + Email: params.Email, + }: + case <-time.After(time.Second * 2): + log.NewWarn(params.OperationID, utils.GetSelfFuncName(), "to ch timeOut") + } } c.JSON(http.StatusOK, gin.H{"errCode": constant.NoError, "errMsg": "", "data": openIMRegisterResp.UserToken}) return diff --git a/internal/rpc/cache/cache.go b/internal/rpc/cache/cache.go index 79d86f2b8..11636ceab 100644 --- a/internal/rpc/cache/cache.go +++ b/internal/rpc/cache/cache.go @@ -3,20 +3,16 @@ package cache import ( "Open_IM/pkg/common/config" "Open_IM/pkg/common/constant" - "Open_IM/pkg/common/db" - imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/db/rocks_cache" "Open_IM/pkg/common/log" "Open_IM/pkg/grpc-etcdv3/getcdv3" pbCache "Open_IM/pkg/proto/cache" - commonPb "Open_IM/pkg/proto/sdk_ws" "Open_IM/pkg/utils" "context" + "google.golang.org/grpc" "net" "strconv" "strings" - "sync" - - "google.golang.org/grpc" ) type cacheServer struct { @@ -54,13 +50,6 @@ func (s *cacheServer) Run() { defer listener.Close() //grpc server - //to cache - err = SyncDB2Cache() - if err != nil { - log.NewError("", err.Error(), "db to cache failed") - panic(err.Error()) - } - srv := grpc.NewServer() defer srv.GracefulStop() pbCache.RegisterCacheServer(srv, s) @@ -86,167 +75,10 @@ func (s *cacheServer) Run() { log.NewInfo("0", "message cms rpc success") } -func SyncDB2Cache() error { - var err error - log.NewInfo("0", utils.GetSelfFuncName()) - userList, err := imdb.GetAllUser() - log.NewDebug("", utils.GetSelfFuncName(), "userList", userList) - if err != nil { - return utils.Wrap(err, "") - } - //err = updateAllUserToCache(userList) - wg := &sync.WaitGroup{} - wg.Add(3) - go func() { - defer wg.Done() - err = updateAllFriendToCache(userList) - }() - go func() { - defer wg.Done() - err = updateAllBlackListToCache(userList) - }() - go func() { - defer wg.Done() - err = updateAllGroupMemberListToCache() - }() - wg.Wait() - return utils.Wrap(err, "") -} - -func DelRelationCache() {} - -func updateAllUserToCache(userList []db.User) error { - wg := &sync.WaitGroup{} - wg.Add(len(userList)) - for _, userInfo := range userList { - go func() { - defer wg.Done() - userInfoPb := &commonPb.UserInfo{ - UserID: userInfo.UserID, - Nickname: userInfo.Nickname, - FaceURL: userInfo.FaceURL, - Gender: userInfo.Gender, - PhoneNumber: userInfo.PhoneNumber, - Birth: uint32(userInfo.Birth.Unix()), - Email: userInfo.Email, - Ex: userInfo.Ex, - CreateTime: uint32(userInfo.CreateTime.Unix()), - AppMangerLevel: userInfo.AppMangerLevel, - } - m, err := utils.Pb2Map(userInfoPb) - if err != nil { - log.NewWarn("", utils.GetSelfFuncName(), err.Error()) - } - if err := db.DB.SetUserInfoToCache(userInfo.UserID, m); err != nil { - log.NewWarn("0", utils.GetSelfFuncName(), "set userInfo to cache failed", err.Error()) - } - }() - } - wg.Wait() - log.NewInfo("0", utils.GetSelfFuncName(), "ok") - return nil -} - -func updateAllGroupMemberListToCache() error { - log.NewInfo("0", utils.GetSelfFuncName()) - groupIDList, err := imdb.GetAllGroupIDList() - if err != nil { - log.NewWarn("0", utils.GetSelfFuncName(), "getAllGroupIDList failed", err.Error()) - panic(err.Error()) - } - - for _, groupID := range groupIDList { - groupMemberIDList, err := imdb.GetGroupMemberIDListByGroupID(groupID) - if err != nil { - log.NewWarn("", utils.GetSelfFuncName(), "GetGroupMemberIDListByGroupID", err.Error()) - continue - } - if len(groupMemberIDList) > 0 { - if err := db.DB.AddGroupMemberToCache(groupID, groupMemberIDList...); err != nil { - log.NewWarn("", utils.GetSelfFuncName(), "AddGroupMemberToCache", err.Error()) - } - } - } - log.NewInfo("0", utils.GetSelfFuncName(), "ok") - return nil -} - -func updateAllFriendToCache(userList []db.User) error { - log.NewInfo("0", utils.GetSelfFuncName()) - for _, user := range userList { - friendIDList, err := imdb.GetFriendIDListByUserID(user.UserID) - if err != nil { - log.NewWarn("0", utils.GetSelfFuncName(), err.Error()) - continue - } - if len(friendIDList) > 0 { - if err := db.DB.AddFriendToCache(user.UserID, friendIDList...); err != nil { - log.NewWarn("0", utils.GetSelfFuncName(), err.Error(), friendIDList, user.UserID) - } - } - } - - log.NewInfo("0", utils.GetSelfFuncName(), "ok") - return nil -} - -func updateAllBlackListToCache(userList []db.User) error { - log.NewInfo("0", utils.GetSelfFuncName()) - for _, user := range userList { - blackIDList, err := imdb.GetBlackIDListByUserID(user.UserID) - if err != nil { - log.NewWarn("", utils.GetSelfFuncName(), err.Error()) - continue - } - if len(blackIDList) > 0 { - if err := db.DB.AddBlackUserToCache(user.UserID, blackIDList...); err != nil { - log.NewWarn("0", utils.GetSelfFuncName(), err.Error()) - } - } - } - log.NewInfo("0", utils.GetSelfFuncName(), "ok") - return nil -} - -func (s *cacheServer) GetUserInfoFromCache(_ context.Context, req *pbCache.GetUserInfoFromCacheReq) (resp *pbCache.GetUserInfoFromCacheResp, err error) { - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) - resp = &pbCache.GetUserInfoFromCacheResp{ - CommonResp: &pbCache.CommonResp{}, - } - for _, userID := range req.UserIDList { - userInfo, err := db.DB.GetUserInfoFromCache(userID) - if err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), "get userInfo from cache failed", err.Error()) - continue - } - resp.UserInfoList = append(resp.UserInfoList, userInfo) - } - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) - return resp, nil -} - -func (s *cacheServer) UpdateUserInfoToCache(_ context.Context, req *pbCache.UpdateUserInfoToCacheReq) (resp *pbCache.UpdateUserInfoToCacheResp, err error) { - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) - resp = &pbCache.UpdateUserInfoToCacheResp{ - CommonResp: &pbCache.CommonResp{}, - } - for _, userInfo := range req.UserInfoList { - m, err := utils.Pb2Map(userInfo) - if err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), *userInfo) - } - if err := db.DB.SetUserInfoToCache(userInfo.UserID, m); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), "set userInfo to cache failed", err.Error()) - } - } - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) - return resp, nil -} - func (s *cacheServer) GetFriendIDListFromCache(_ context.Context, req *pbCache.GetFriendIDListFromCacheReq) (resp *pbCache.GetFriendIDListFromCacheResp, err error) { log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) resp = &pbCache.GetFriendIDListFromCacheResp{CommonResp: &pbCache.CommonResp{}} - friendIDList, err := db.DB.GetFriendIDListFromCache(req.UserID) + friendIDList, err := rocksCache.GetFriendIDListFromCache(req.UserID) if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetFriendIDListFromCache", err.Error()) resp.CommonResp.ErrCode = constant.ErrDB.ErrCode @@ -259,36 +91,24 @@ func (s *cacheServer) GetFriendIDListFromCache(_ context.Context, req *pbCache.G return resp, nil } -func (s *cacheServer) AddFriendToCache(_ context.Context, req *pbCache.AddFriendToCacheReq) (resp *pbCache.AddFriendToCacheResp, err error) { +// this is for dtm call +func (s *cacheServer) DelFriendIDListFromCache(_ context.Context, req *pbCache.DelFriendIDListFromCacheReq) (resp *pbCache.DelFriendIDListFromCacheResp, err error) { log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) - resp = &pbCache.AddFriendToCacheResp{CommonResp: &pbCache.CommonResp{}} - if err := db.DB.AddFriendToCache(req.UserID, req.FriendID); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", err.Error()) + resp = &pbCache.DelFriendIDListFromCacheResp{} + if err := rocksCache.DelFriendIDListFromCache(req.UserID); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "args: ", req.UserID, err.Error()) resp.CommonResp.ErrCode = constant.ErrDB.ErrCode - resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg - return resp, nil - } - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) - return resp, nil -} - -func (s *cacheServer) ReduceFriendFromCache(_ context.Context, req *pbCache.ReduceFriendFromCacheReq) (resp *pbCache.ReduceFriendFromCacheResp, err error) { - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) - resp = &pbCache.ReduceFriendFromCacheResp{CommonResp: &pbCache.CommonResp{}} - if err := db.DB.ReduceFriendToCache(req.UserID, req.FriendID); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", err.Error()) - resp.CommonResp.ErrCode = constant.ErrDB.ErrCode - resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg + resp.CommonResp.ErrMsg = err.Error() return resp, nil } - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", resp.String()) return resp, nil } func (s *cacheServer) GetBlackIDListFromCache(_ context.Context, req *pbCache.GetBlackIDListFromCacheReq) (resp *pbCache.GetBlackIDListFromCacheResp, err error) { log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) resp = &pbCache.GetBlackIDListFromCacheResp{CommonResp: &pbCache.CommonResp{}} - blackUserIDList, err := db.DB.GetBlackListFromCache(req.UserID) + blackUserIDList, err := rocksCache.GetBlackListFromCache(req.UserID) if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", err.Error()) resp.CommonResp.ErrCode = constant.ErrDB.ErrCode @@ -301,29 +121,16 @@ func (s *cacheServer) GetBlackIDListFromCache(_ context.Context, req *pbCache.Ge return resp, nil } -func (s *cacheServer) AddBlackUserToCache(_ context.Context, req *pbCache.AddBlackUserToCacheReq) (resp *pbCache.AddBlackUserToCacheResp, err error) { - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) - resp = &pbCache.AddBlackUserToCacheResp{CommonResp: &pbCache.CommonResp{}} - if err := db.DB.AddBlackUserToCache(req.UserID, req.BlackUserID); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error()) - resp.CommonResp.ErrCode = constant.ErrDB.ErrCode - resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg - return resp, nil - } - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) - return resp, nil -} - -func (s *cacheServer) ReduceBlackUserFromCache(_ context.Context, req *pbCache.ReduceBlackUserFromCacheReq) (resp *pbCache.ReduceBlackUserFromCacheResp, err error) { +func (s *cacheServer) DelBlackIDListFromCache(_ context.Context, req *pbCache.DelBlackIDListFromCacheReq) (resp *pbCache.DelBlackIDListFromCacheResp, err error) { log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) - resp = &pbCache.ReduceBlackUserFromCacheResp{CommonResp: &pbCache.CommonResp{}} - if err := db.DB.ReduceBlackUserFromCache(req.UserID, req.BlackUserID); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error()) + resp = &pbCache.DelBlackIDListFromCacheResp{} + if err := rocksCache.DelBlackIDListFromCache(req.UserID); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "args: ", req.UserID, err.Error()) resp.CommonResp.ErrCode = constant.ErrDB.ErrCode - resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg + resp.CommonResp.ErrMsg = err.Error() return resp, nil } - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", resp.String()) return resp, nil } @@ -332,7 +139,7 @@ func (s *cacheServer) GetGroupMemberIDListFromCache(_ context.Context, req *pbCa resp = &pbCache.GetGroupMemberIDListFromCacheResp{ CommonResp: &pbCache.CommonResp{}, } - userIDList, err := db.DB.GetGroupMemberIDListFromCache(req.GroupID) + userIDList, err := rocksCache.GetGroupMemberIDListFromCache(req.GroupID) if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetGroupMemberIDListFromCache failed", err.Error()) resp.CommonResp.ErrCode = constant.ErrDB.ErrCode @@ -344,28 +151,15 @@ func (s *cacheServer) GetGroupMemberIDListFromCache(_ context.Context, req *pbCa return resp, nil } -func (s *cacheServer) AddGroupMemberToCache(_ context.Context, req *pbCache.AddGroupMemberToCacheReq) (resp *pbCache.AddGroupMemberToCacheResp, err error) { +func (s *cacheServer) DelGroupMemberIDListFromCache(_ context.Context, req *pbCache.DelGroupMemberIDListFromCacheReq) (resp *pbCache.DelGroupMemberIDListFromCacheResp, err error) { log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) - resp = &pbCache.AddGroupMemberToCacheResp{CommonResp: &pbCache.CommonResp{}} - if err := db.DB.AddGroupMemberToCache(req.GroupID, req.UserIDList...); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), "AddGroupMemberToCache failed", err.Error()) + resp = &pbCache.DelGroupMemberIDListFromCacheResp{} + if err := rocksCache.DelGroupMemberIDListFromCache(req.GroupID); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "args: ", req.GroupID, err.Error()) resp.CommonResp.ErrCode = constant.ErrDB.ErrCode - resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg + resp.CommonResp.ErrMsg = err.Error() return resp, nil } - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) - return resp, nil -} - -func (s *cacheServer) ReduceGroupMemberFromCache(_ context.Context, req *pbCache.ReduceGroupMemberFromCacheReq) (resp *pbCache.ReduceGroupMemberFromCacheResp, err error) { - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", req.String()) - resp = &pbCache.ReduceGroupMemberFromCacheResp{CommonResp: &pbCache.CommonResp{}} - if err := db.DB.ReduceGroupMemberFromCache(req.GroupID, req.UserIDList...); err != nil { - log.NewError(req.OperationID, utils.GetSelfFuncName(), "ReduceGroupMemberFromCache failed", err.Error()) - resp.CommonResp.ErrCode = constant.ErrDB.ErrCode - resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg - return resp, nil - } - log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp.String()) + log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "req: ", resp.String()) return resp, nil } diff --git a/internal/rpc/friend/firend.go b/internal/rpc/friend/friend.go similarity index 86% rename from internal/rpc/friend/firend.go rename to internal/rpc/friend/friend.go index 5c2c2a359..6d1f22346 100644 --- a/internal/rpc/friend/firend.go +++ b/internal/rpc/friend/friend.go @@ -6,6 +6,7 @@ import ( "Open_IM/pkg/common/constant" "Open_IM/pkg/common/db" imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/db/rocks_cache" "Open_IM/pkg/common/log" "Open_IM/pkg/common/token_verify" cp "Open_IM/pkg/common/utils" @@ -95,10 +96,10 @@ func (s *friendServer) AddBlacklist(ctx context.Context, req *pbFriend.AddBlackl err := imdb.InsertInToUserBlackList(black) if err != nil { log.NewError(req.CommID.OperationID, "InsertInToUserBlackList failed ", err.Error()) - return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil + return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil } log.NewInfo(req.CommID.OperationID, "AddBlacklist rpc ok ", req.CommID.FromUserID, req.CommID.ToUserID) - reqAddBlackUserToCache := &pbCache.AddBlackUserToCacheReq{UserID: req.CommID.FromUserID, BlackUserID: req.CommID.ToUserID, OperationID: req.CommID.OperationID} + etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.CommID.OperationID) if etcdConn == nil { errMsg := req.CommID.OperationID + "getcdv3.GetConn == nil" @@ -106,15 +107,16 @@ func (s *friendServer) AddBlacklist(ctx context.Context, req *pbFriend.AddBlackl return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil } cacheClient := pbCache.NewCacheClient(etcdConn) - cacheResp, err := cacheClient.AddBlackUserToCache(context.Background(), reqAddBlackUserToCache) + cacheResp, err := cacheClient.DelBlackIDListFromCache(context.Background(), &pbCache.DelBlackIDListFromCacheReq{UserID: req.CommID.FromUserID, OperationID: req.CommID.OperationID}) if err != nil { - log.NewError(req.CommID.OperationID, "AddBlackUserToCache rpc call failed ", err.Error()) + log.NewError(req.CommID.OperationID, "DelBlackIDListFromCache rpc call failed ", err.Error()) return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: 500, ErrMsg: "AddBlackUserToCache rpc call failed"}}, nil } if cacheResp.CommonResp.ErrCode != 0 { - log.NewError(req.CommID.OperationID, "AddBlackUserToCache rpc logic call failed ", cacheResp.String()) + log.NewError(req.CommID.OperationID, "DelBlackIDListFromCache rpc logic call failed ", cacheResp.String()) return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}}, nil } + chat.BlackAddedNotification(req) return &pbFriend.AddBlacklistResp{CommonResp: &pbFriend.CommonResp{}}, nil } @@ -208,6 +210,30 @@ func (s *friendServer) ImportFriend(ctx context.Context, req *pbFriend.ImportFri } } } + + etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID) + if etcdConn == nil { + errMsg := req.OperationID + "getcdv3.GetConn == nil" + log.NewError(req.OperationID, errMsg) + resp.CommonResp.ErrMsg = errMsg + resp.CommonResp.ErrCode = 500 + return &resp, nil + } + cacheClient := pbCache.NewCacheClient(etcdConn) + cacheResp, err := cacheClient.DelFriendIDListFromCache(context.Background(), &pbCache.DelFriendIDListFromCacheReq{UserID: req.FromUserID, OperationID: req.OperationID}) + if err != nil { + log.NewError(req.OperationID, "DelBlackIDListFromCache rpc call failed ", err.Error()) + resp.CommonResp.ErrCode = 500 + resp.CommonResp.ErrMsg = err.Error() + return &resp, nil + } + if cacheResp.CommonResp.ErrCode != 0 { + log.NewError(req.OperationID, "DelBlackIDListFromCache rpc logic call failed ", cacheResp.String()) + resp.CommonResp.ErrCode = 500 + resp.CommonResp.ErrMsg = cacheResp.CommonResp.ErrMsg + return &resp, nil + } + resp.CommonResp.ErrCode = 0 log.NewInfo(req.OperationID, "ImportFriend rpc ok ", resp.String()) return &resp, nil @@ -267,7 +293,7 @@ func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddF return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } // cache rpc - addFriendToCacheReq := &pbCache.AddFriendToCacheReq{OperationID: req.CommID.OperationID} + delFriendIDListFromCacheReq := &pbCache.DelFriendIDListFromCacheReq{OperationID: req.CommID.OperationID} etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.CommID.OperationID) if etcdConn == nil { errMsg := req.CommID.OperationID + "getcdv3.GetConn == nil" @@ -275,29 +301,26 @@ func (s *friendServer) AddFriendResponse(ctx context.Context, req *pbFriend.AddF return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil } client := pbCache.NewCacheClient(etcdConn) - addFriendToCacheReq.UserID = req.CommID.ToUserID - addFriendToCacheReq.FriendID = req.CommID.FromUserID - respPb, err := client.AddFriendToCache(context.Background(), addFriendToCacheReq) + delFriendIDListFromCacheReq.UserID = req.CommID.ToUserID + respPb, err := client.DelFriendIDListFromCache(context.Background(), delFriendIDListFromCacheReq) if err != nil { - log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", err.Error(), addFriendToCacheReq.String()) + log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "DelFriendIDListFromCache failed", err.Error()) return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrServer.ErrCode, ErrMsg: constant.ErrServer.ErrMsg}}, nil } if respPb.CommonResp.ErrCode != 0 { - log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", addFriendToCacheReq.String()) + log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "DelFriendIDListFromCache failed", respPb.CommonResp.String()) return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: respPb.CommonResp.ErrCode, ErrMsg: respPb.CommonResp.ErrMsg}}, nil } - addFriendToCacheReq.UserID = req.CommID.FromUserID - addFriendToCacheReq.FriendID = req.CommID.ToUserID - respPb, err = client.AddFriendToCache(context.Background(), addFriendToCacheReq) + delFriendIDListFromCacheReq.UserID = req.CommID.FromUserID + respPb, err = client.DelFriendIDListFromCache(context.Background(), delFriendIDListFromCacheReq) if err != nil { - log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", err.Error(), addFriendToCacheReq.String()) + log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "DelFriendIDListFromCache failed", err.Error()) return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrServer.ErrCode, ErrMsg: constant.ErrServer.ErrMsg}}, nil } if respPb.CommonResp.ErrCode != 0 { - log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed", addFriendToCacheReq.String()) + log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "DelFriendIDListFromCache failed", respPb.CommonResp.String()) return &pbFriend.AddFriendResponseResp{CommonResp: &pbFriend.CommonResp{ErrCode: respPb.CommonResp.ErrCode, ErrMsg: respPb.CommonResp.ErrMsg}}, nil } - chat.FriendAddedNotification(req.CommID.OperationID, req.CommID.OpUserID, req.CommID.FromUserID, req.CommID.ToUserID) } } @@ -327,7 +350,7 @@ func (s *friendServer) DeleteFriend(ctx context.Context, req *pbFriend.DeleteFri return &pbFriend.DeleteFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil } log.NewInfo(req.CommID.OperationID, "DeleteFriend rpc ok") - reduceFriendFromCache := &pbCache.ReduceFriendFromCacheReq{OperationID: req.CommID.OperationID, UserID: req.CommID.FromUserID, FriendID: req.CommID.ToUserID} + etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.CommID.OperationID) if etcdConn == nil { errMsg := req.CommID.OperationID + "getcdv3.GetConn == nil" @@ -335,13 +358,13 @@ func (s *friendServer) DeleteFriend(ctx context.Context, req *pbFriend.DeleteFri return &pbFriend.DeleteFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil } client := pbCache.NewCacheClient(etcdConn) - respPb, err := client.ReduceFriendFromCache(context.Background(), reduceFriendFromCache) + respPb, err := client.DelFriendIDListFromCache(context.Background(), &pbCache.DelFriendIDListFromCacheReq{OperationID: req.CommID.OperationID, UserID: req.CommID.FromUserID}) if err != nil { - log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "AddFriendToCache rpc failed", err.Error()) + log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "DelFriendIDListFromCache rpc failed", err.Error()) return &pbFriend.DeleteFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrServer.ErrCode, ErrMsg: constant.ErrServer.ErrMsg}}, nil } if respPb.CommonResp.ErrCode != 0 { - log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "AddFriendToCache failed") + log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "DelFriendIDListFromCache failed", respPb.CommonResp.String()) return &pbFriend.DeleteFriendResp{CommonResp: &pbFriend.CommonResp{ErrCode: respPb.CommonResp.ErrCode, ErrMsg: respPb.CommonResp.ErrMsg}}, nil } chat.FriendDeletedNotification(req) @@ -351,13 +374,12 @@ func (s *friendServer) DeleteFriend(ctx context.Context, req *pbFriend.DeleteFri func (s *friendServer) GetBlacklist(ctx context.Context, req *pbFriend.GetBlacklistReq) (*pbFriend.GetBlacklistResp, error) { log.NewInfo(req.CommID.OperationID, "GetBlacklist args ", req.String()) - //Parse token, to find current user information if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) { log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID) return &pbFriend.GetBlacklistResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil } - blackListInfo, err := imdb.GetBlackListByUserID(req.CommID.FromUserID) + blackIDList, err := rocksCache.GetBlackListFromCache(req.CommID.FromUserID) if err != nil { log.NewError(req.CommID.OperationID, "GetBlackListByUID failed ", err.Error(), req.CommID.FromUserID) return &pbFriend.GetBlacklistResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil @@ -366,15 +388,14 @@ func (s *friendServer) GetBlacklist(ctx context.Context, req *pbFriend.GetBlackl var ( userInfoList []*sdkws.PublicUserInfo ) - for _, blackUser := range blackListInfo { - var blackUserInfo sdkws.PublicUserInfo - //Find black user information - us, err := imdb.GetUserByUserID(blackUser.BlockUserID) + for _, userID := range blackIDList { + user, err := rocksCache.GetUserInfoFromCache(userID) if err != nil { - log.NewError(req.CommID.OperationID, "GetUserByUserID failed ", err.Error(), blackUser.BlockUserID) + log.NewError(req.CommID.OperationID, "GetUserByUserID failed ", err.Error(), userID) continue } - utils.CopyStructFields(&blackUserInfo, us) + var blackUserInfo sdkws.PublicUserInfo + utils.CopyStructFields(&blackUserInfo, user) userInfoList = append(userInfoList, &blackUserInfo) } log.NewInfo(req.CommID.OperationID, "rpc GetBlacklist ok ", pbFriend.GetBlacklistResp{BlackUserInfoList: userInfoList}) @@ -391,10 +412,15 @@ func (s *friendServer) SetFriendRemark(ctx context.Context, req *pbFriend.SetFri err := imdb.UpdateFriendComment(req.CommID.FromUserID, req.CommID.ToUserID, req.Remark) if err != nil { - log.NewError(req.CommID.OperationID, "UpdateFriendComment failed ", req.CommID.FromUserID, req.CommID.ToUserID, req.Remark) + log.NewError(req.CommID.OperationID, "UpdateFriendComment failed ", req.CommID.FromUserID, req.CommID.ToUserID, req.Remark, err.Error()) return &pbFriend.SetFriendRemarkResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } log.NewInfo(req.CommID.OperationID, "rpc SetFriendComment ok") + err = rocksCache.DelAllFriendsInfoFromCache(req.CommID.FromUserID) + if err != nil { + log.NewError(req.CommID.OperationID, "DelAllFriendInfoFromCache failed ", req.CommID.FromUserID, err.Error()) + return &pbFriend.SetFriendRemarkResp{CommonResp: &pbFriend.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil + } chat.FriendRemarkSetNotification(req.CommID.OperationID, req.CommID.OpUserID, req.CommID.FromUserID, req.CommID.ToUserID) return &pbFriend.SetFriendRemarkResp{CommonResp: &pbFriend.CommonResp{}}, nil } @@ -413,7 +439,7 @@ func (s *friendServer) RemoveBlacklist(ctx context.Context, req *pbFriend.Remove } log.NewInfo(req.CommID.OperationID, "rpc RemoveBlacklist ok ") - reqReduceBlackUserFromCache := &pbCache.ReduceBlackUserFromCacheReq{UserID: req.CommID.FromUserID, BlackUserID: req.CommID.ToUserID, OperationID: req.CommID.OperationID} + etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.CommID.OperationID) if etcdConn == nil { errMsg := req.CommID.OperationID + "getcdv3.GetConn == nil" @@ -422,13 +448,13 @@ func (s *friendServer) RemoveBlacklist(ctx context.Context, req *pbFriend.Remove } cacheClient := pbCache.NewCacheClient(etcdConn) - cacheResp, err := cacheClient.ReduceBlackUserFromCache(context.Background(), reqReduceBlackUserFromCache) + cacheResp, err := cacheClient.DelBlackIDListFromCache(context.Background(), &pbCache.DelBlackIDListFromCacheReq{UserID: req.CommID.FromUserID, OperationID: req.CommID.OperationID}) if err != nil { - log.NewError(req.CommID.OperationID, "ReduceBlackUserFromCache rpc call failed ", err.Error()) + log.NewError(req.CommID.OperationID, "DelBlackIDListFromCache rpc call failed ", err.Error()) return &pbFriend.RemoveBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: 500, ErrMsg: "ReduceBlackUserFromCache rpc call failed"}}, nil } if cacheResp.CommonResp.ErrCode != 0 { - log.NewError(req.CommID.OperationID, "ReduceBlackUserFromCache rpc logic call failed ", cacheResp.String()) + log.NewError(req.CommID.OperationID, "DelBlackIDListFromCache rpc logic call failed ", cacheResp.CommonResp.String()) return &pbFriend.RemoveBlacklistResp{CommonResp: &pbFriend.CommonResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}}, nil } chat.BlackDeletedNotification(req) @@ -441,10 +467,13 @@ func (s *friendServer) IsInBlackList(ctx context.Context, req *pbFriend.IsInBlac log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID) return &pbFriend.IsInBlackListResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil } - - var isInBlacklist = false - err := imdb.CheckBlack(req.CommID.FromUserID, req.CommID.ToUserID) - if err == nil { + blackIDList, err := rocksCache.GetBlackListFromCache(req.CommID.FromUserID) + if err != nil { + log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), err.Error(), req.CommID.FromUserID) + return &pbFriend.IsInBlackListResp{ErrMsg: err.Error(), ErrCode: constant.ErrDB.ErrCode}, nil + } + var isInBlacklist bool + if utils.IsContain(req.CommID.ToUserID, blackIDList) { isInBlacklist = true } log.NewInfo(req.CommID.OperationID, "IsInBlackList rpc ok ", pbFriend.IsInBlackListResp{Response: isInBlacklist}) @@ -453,16 +482,18 @@ func (s *friendServer) IsInBlackList(ctx context.Context, req *pbFriend.IsInBlac func (s *friendServer) IsFriend(ctx context.Context, req *pbFriend.IsFriendReq) (*pbFriend.IsFriendResp, error) { log.NewInfo(req.CommID.OperationID, req.String()) - var isFriend bool if !token_verify.CheckAccess(req.CommID.OpUserID, req.CommID.FromUserID) { log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID) return &pbFriend.IsFriendResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil } - _, err := imdb.GetFriendRelationshipFromFriend(req.CommID.FromUserID, req.CommID.ToUserID) - if err == nil { + friendIDList, err := rocksCache.GetFriendIDListFromCache(req.CommID.FromUserID) + if err != nil { + log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), err.Error(), req.CommID.FromUserID) + return &pbFriend.IsFriendResp{ErrMsg: err.Error(), ErrCode: constant.ErrDB.ErrCode}, nil + } + var isFriend bool + if utils.IsContain(req.CommID.ToUserID, friendIDList) { isFriend = true - } else { - isFriend = false } log.NewInfo(req.CommID.OperationID, pbFriend.IsFriendResp{Response: isFriend}) return &pbFriend.IsFriendResp{Response: isFriend}, nil @@ -474,16 +505,16 @@ func (s *friendServer) GetFriendList(ctx context.Context, req *pbFriend.GetFrien log.NewError(req.CommID.OperationID, "CheckAccess false ", req.CommID.OpUserID, req.CommID.FromUserID) return &pbFriend.GetFriendListResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil } - - friends, err := imdb.GetFriendListByUserID(req.CommID.FromUserID) + friendList, err := rocksCache.GetAllFriendsInfoFromCache(req.CommID.FromUserID) if err != nil { - log.NewError(req.CommID.OperationID, "FindUserInfoFromFriend failed ", err.Error(), req.CommID.FromUserID) + log.NewError(req.CommID.OperationID, utils.GetSelfFuncName(), "GetFriendIDListFromCache failed", err.Error(), req.CommID.FromUserID) return &pbFriend.GetFriendListResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil } + var userInfoList []*sdkws.FriendInfo - for _, friendUser := range friends { + for _, friendUser := range friendList { friendUserInfo := sdkws.FriendInfo{FriendUser: &sdkws.UserInfo{}} - cp.FriendDBCopyOpenIM(&friendUserInfo, &friendUser) + cp.FriendDBCopyOpenIM(&friendUserInfo, friendUser) log.NewDebug(req.CommID.OperationID, "friends : ", friendUser, "openim friends: ", friendUserInfo) userInfoList = append(userInfoList, &friendUserInfo) } diff --git a/internal/rpc/group/group.go b/internal/rpc/group/group.go index ea46bb005..f5510ded5 100644 --- a/internal/rpc/group/group.go +++ b/internal/rpc/group/group.go @@ -6,6 +6,7 @@ import ( "Open_IM/pkg/common/constant" "Open_IM/pkg/common/db" imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/db/rocks_cache" "Open_IM/pkg/common/http" "Open_IM/pkg/common/log" "Open_IM/pkg/common/token_verify" @@ -159,7 +160,8 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR return resp, nil } utils.CopyStructFields(resp.GroupInfo, group) - resp.GroupInfo.MemberCount, err = imdb.GetGroupMemberNumByGroupID(groupId) + memberCount, err := imdb.GetGroupMemberNumByGroupID(groupId) + resp.GroupInfo.MemberCount = uint32(memberCount) if err != nil { log.NewError(req.OperationID, "GetGroupMemberNumByGroupID failed ", err.Error(), groupId) resp.ErrCode = constant.ErrDB.ErrCode @@ -182,28 +184,6 @@ func (s *groupServer) CreateGroup(ctx context.Context, req *pbGroup.CreateGroupR } if len(okUserIDList) != 0 { - addGroupMemberToCacheReq := &pbCache.AddGroupMemberToCacheReq{ - UserIDList: okUserIDList, - GroupID: groupId, - OperationID: req.OperationID, - } - etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID) - if etcdConn == nil { - errMsg := req.OperationID + "getcdv3.GetConn == nil" - log.NewError(req.OperationID, errMsg) - return &pbGroup.CreateGroupResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}, nil - } - cacheClient := pbCache.NewCacheClient(etcdConn) - cacheResp, err := cacheClient.AddGroupMemberToCache(context.Background(), addGroupMemberToCacheReq) - if err != nil { - log.NewError(req.OperationID, "AddGroupMemberToCache rpc call failed ", err.Error()) - return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil - } - if cacheResp.CommonResp.ErrCode != 0 { - log.NewError(req.OperationID, "AddGroupMemberToCache rpc logic call failed ", cacheResp.String()) - return &pbGroup.CreateGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil - } - log.NewInfo(req.OperationID, "rpc CreateGroup return ", resp.String()) if req.GroupInfo.GroupType != constant.SuperGroup { chat.GroupCreatedNotification(req.OperationID, req.OpUserID, groupId, okUserIDList) @@ -227,10 +207,10 @@ func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJo log.NewError(req.OperationID, "CheckAccess false ", req.OpUserID, req.FromUserID) return &pbGroup.GetJoinedGroupListResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}, nil } - //group list - joinedGroupList, err := imdb.GetJoinedGroupIDListByUserID(req.FromUserID) + + joinedGroupList, err := rocksCache.GetJoinedGroupIDListFromCache(req.FromUserID) if err != nil { - log.NewError(req.OperationID, "GetJoinedGroupIDListByUserID failed ", err.Error(), req.FromUserID) + log.NewError(req.OperationID, utils.GetSelfFuncName(), "GetJoinedGroupIDListFromCache failed", err.Error(), req.FromUserID) return &pbGroup.GetJoinedGroupListResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil } @@ -238,8 +218,14 @@ func (s *groupServer) GetJoinedGroupList(ctx context.Context, req *pbGroup.GetJo for _, v := range joinedGroupList { var groupNode open_im_sdk.GroupInfo num, err := imdb.GetGroupMemberNumByGroupID(v) - owner, err2 := imdb.GetGroupOwnerInfoByGroupID(v) - group, err := imdb.GetGroupInfoByGroupID(v) + + groupOwnerID, err2 := rocksCache.GetGroupOwnerFromCache(v) + owner, err2 := rocksCache.GetGroupMemberInfoFromCache(v, groupOwnerID) + //owner, err2 := imdb.GetGroupOwnerInfoByGroupID(v) + + group, err := rocksCache.GetGroupInfoFromCache(v) + //group, err := imdb.GetGroupInfoByGroupID(v) + if num > 0 && owner != nil && err2 == nil && group != nil && err == nil { utils.CopyStructFields(&groupNode, group) groupNode.CreateTime = uint32(group.CreateTime.Unix()) @@ -416,11 +402,7 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite } } - addGroupMemberToCacheReq := &pbCache.AddGroupMemberToCacheReq{ - UserIDList: okUserIDList, - GroupID: req.GroupID, - OperationID: req.OperationID, - } + etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID) if etcdConn == nil { errMsg := req.OperationID + "getcdv3.GetConn == nil" @@ -428,17 +410,23 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}, nil } cacheClient := pbCache.NewCacheClient(etcdConn) - cacheResp, err := cacheClient.AddGroupMemberToCache(context.Background(), addGroupMemberToCacheReq) + cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{ + GroupID: req.GroupID, + OperationID: req.OperationID, + }) if err != nil { - log.NewError(req.OperationID, "AddGroupMemberToCache rpc call failed ", err.Error()) + log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error()) return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil } if cacheResp.CommonResp.ErrCode != 0 { - log.NewError(req.OperationID, "AddGroupMemberToCache rpc logic call failed ", cacheResp.String()) + log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String()) return &pbGroup.InviteUserToGroupResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil } if groupInfo.GroupType != constant.SuperGroup { + if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) + } chat.MemberInvitedNotification(req.OperationID, req.GroupID, req.OpUserID, req.Reason, okUserIDList) } else { go func() { @@ -455,7 +443,8 @@ func (s *groupServer) InviteUserToGroup(ctx context.Context, req *pbGroup.Invite func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGroupAllMemberReq) (*pbGroup.GetGroupAllMemberResp, error) { log.NewInfo(req.OperationID, "GetGroupAllMember, args ", req.String()) var resp pbGroup.GetGroupAllMemberResp - groupInfo, err := imdb.GetGroupInfoByGroupID(req.GroupID) + //groupInfo, err := imdb.GetGroupInfoByGroupID(req.GroupID) + groupInfo, err := rocksCache.GetGroupInfoFromCache(req.GroupID) if err != nil { log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) resp.ErrCode = constant.ErrDB.ErrCode @@ -463,18 +452,23 @@ func (s *groupServer) GetGroupAllMember(ctx context.Context, req *pbGroup.GetGro return &resp, nil } if groupInfo.GroupType != constant.SuperGroup { - memberList, err := imdb.GetGroupMemberListByGroupID(req.GroupID) + memberList, err := rocksCache.GetAllGroupMembersInfoFromCache(req.GroupID) if err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) resp.ErrCode = constant.ErrDB.ErrCode resp.ErrMsg = constant.ErrDB.ErrMsg - log.NewError(req.OperationID, "GetGroupMemberListByGroupID failed,", err.Error(), req.GroupID) return &resp, nil } - + //memberList, err := imdb.GetGroupMemberListByGroupID(req.GroupID) + //if err != nil { + // log.NewError(req.OperationID, "GetGroupMemberListByGroupID failed,", err.Error(), req.GroupID) + // resp.ErrCode = constant.ErrDB.ErrCode + // resp.ErrMsg = constant.ErrDB.ErrMsg + // return &resp, nil + //} for _, v := range memberList { - //log.Debug(req.OperationID, v) var node open_im_sdk.GroupMemberFullInfo - cp.GroupMemberDBCopyOpenIM(&node, &v) + cp.GroupMemberDBCopyOpenIM(&node, v) //log.Debug(req.OperationID, "db value:", v.MuteEndTime, "seconds: ", v.MuteEndTime.Unix()) //log.Debug(req.OperationID, "cp value: ", node) resp.MemberList = append(resp.MemberList, &node) @@ -506,7 +500,6 @@ func (s *groupServer) GetGroupMemberList(ctx context.Context, req *pbGroup.GetGr } else { resp.NextSeq = req.NextSeq + int32(len(memberList)) } - resp.ErrCode = 0 log.NewInfo(req.OperationID, "GetGroupMemberList rpc return ", resp.String()) return &resp, nil @@ -635,11 +628,6 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou } } - reduceGroupMemberFromCacheReq := &pbCache.ReduceGroupMemberFromCacheReq{ - UserIDList: okUserIDList, - GroupID: req.GroupID, - OperationID: req.OperationID, - } etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID) if etcdConn == nil { errMsg := req.OperationID + "getcdv3.GetConn == nil" @@ -647,16 +635,23 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}, nil } cacheClient := pbCache.NewCacheClient(etcdConn) - cacheResp, err := cacheClient.ReduceGroupMemberFromCache(context.Background(), reduceGroupMemberFromCacheReq) + cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{ + GroupID: req.GroupID, + OperationID: req.OperationID, + }) if err != nil { - log.NewError(req.OperationID, "ReduceGroupMemberFromCache rpc call failed ", err.Error()) + log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error()) return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil } if cacheResp.CommonResp.ErrCode != 0 { - log.NewError(req.OperationID, "ReduceGroupMemberFromCache rpc logic call failed ", cacheResp.String()) + log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String()) return &pbGroup.KickGroupMemberResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}, nil } + if groupInfo.GroupType != constant.SuperGroup { + if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) + } chat.MemberKickedNotification(req, okUserIDList) } else { go func() { @@ -664,8 +659,8 @@ func (s *groupServer) KickGroupMember(ctx context.Context, req *pbGroup.KickGrou chat.SuperGroupNotification(req.OperationID, v, v) } }() - } + log.NewInfo(req.OperationID, "GetGroupMemberList rpc return ", resp.String()) return &resp, nil } @@ -674,20 +669,38 @@ func (s *groupServer) GetGroupMembersInfo(ctx context.Context, req *pbGroup.GetG log.NewInfo(req.OperationID, "GetGroupMembersInfo args ", req.String()) var resp pbGroup.GetGroupMembersInfoResp + resp.MemberList = []*open_im_sdk.GroupMemberFullInfo{} + + //for _, v := range req.MemberList { + // var memberNode open_im_sdk.GroupMemberFullInfo + // memberInfo, err := imdb.GetMemberInfoByID(req.GroupID, v) + // memberNode.UserID = v + // if err != nil { + // log.NewError(req.OperationID, "GetMemberInfoById failed ", err.Error(), req.GroupID, v) + // continue + // } else { + // utils.CopyStructFields(&memberNode, memberInfo) + // memberNode.JoinTime = int32(memberInfo.JoinTime.Unix()) + // resp.MemberList = append(resp.MemberList, &memberNode) + // } + //} - for _, v := range req.MemberList { - var memberNode open_im_sdk.GroupMemberFullInfo - memberInfo, err := imdb.GetMemberInfoByID(req.GroupID, v) - memberNode.UserID = v - if err != nil { - log.NewError(req.OperationID, "GetMemberInfoById failed ", err.Error(), req.GroupID, v) - continue - } else { - utils.CopyStructFields(&memberNode, memberInfo) - memberNode.JoinTime = int32(memberInfo.JoinTime.Unix()) + groupMembers, err := rocksCache.GetAllGroupMembersInfoFromCache(req.GroupID) + if err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), req.GroupID, err.Error()) + resp.ErrCode = constant.ErrDB.ErrCode + resp.ErrMsg = constant.ErrDB.ErrMsg + return &resp, nil + } + for _, member := range groupMembers { + if utils.IsContain(member.UserID, req.MemberList) { + var memberNode open_im_sdk.GroupMemberFullInfo + utils.CopyStructFields(&memberNode, member) + memberNode.JoinTime = int32(member.JoinTime.Unix()) resp.MemberList = append(resp.MemberList, &memberNode) } } + resp.ErrCode = 0 log.NewInfo(req.OperationID, "GetGroupMembersInfo rpc return ", resp.String()) return &resp, nil @@ -730,16 +743,17 @@ func (s *groupServer) GetGroupsInfo(ctx context.Context, req *pbGroup.GetGroupsI log.NewInfo(req.OperationID, "GetGroupsInfo args ", req.String()) groupsInfoList := make([]*open_im_sdk.GroupInfo, 0) for _, groupID := range req.GroupIDList { - groupInfoFromMysql, err := imdb.GetGroupInfoByGroupID(groupID) + //groupInfoFromMysql, err := imdb.GetGroupInfoByGroupID(groupID) + groupInfoFromRedis, err := rocksCache.GetGroupInfoFromCache(groupID) if err != nil { log.NewError(req.OperationID, "GetGroupInfoByGroupID failed ", err.Error(), groupID) continue } var groupInfo open_im_sdk.GroupInfo - cp.GroupDBCopyOpenIM(&groupInfo, groupInfoFromMysql) + cp.GroupDBCopyOpenIM(&groupInfo, groupInfoFromRedis) //groupInfo.NeedVerification - groupInfo.NeedVerification = groupInfoFromMysql.NeedVerification + groupInfo.NeedVerification = groupInfoFromRedis.NeedVerification groupsInfoList = append(groupsInfoList, &groupInfo) } @@ -823,23 +837,36 @@ func (s *groupServer) GroupApplicationResponse(_ context.Context, req *pbGroup.G } else { log.NewDebug(req.OperationID, utils.GetSelfFuncName(), "SetConversation success", respPb.String()) } - addGroupMemberToCacheReq := &pbCache.AddGroupMemberToCacheReq{OperationID: req.OperationID, GroupID: req.GroupID, UserIDList: []string{req.FromUserID}} + etcdCacheConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID) - if etcdConn == nil { + if etcdCacheConn == nil { errMsg := req.OperationID + "getcdv3.GetConn == nil" log.NewError(req.OperationID, errMsg) return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil } cacheClient := pbCache.NewCacheClient(etcdCacheConn) - cacheResp, err := cacheClient.AddGroupMemberToCache(context.Background(), addGroupMemberToCacheReq) + cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{OperationID: req.OperationID, GroupID: req.GroupID}) if err != nil { - log.NewError(req.OperationID, "AddGroupMemberToCache rpc call failed ", err.Error()) + log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error()) return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } if cacheResp.CommonResp.ErrCode != 0 { - log.NewError(req.OperationID, "AddGroupMemberToCache rpc logic call failed ", cacheResp.String()) + log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String()) return &pbGroup.GroupApplicationResponseResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } + + group, err := rocksCache.GetGroupInfoFromCache(req.GroupID) + if err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), req.GroupID, err.Error()) + } + if group != nil { + if group.GroupType != constant.SuperGroup { + if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) + } + } + } + chat.GroupApplicationAcceptedNotification(req) chat.MemberEnterNotification(req) } else if req.HandleResult == constant.GroupResponseRefuse { @@ -872,24 +899,19 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) } if groupInfo.NeedVerification == constant.Directly { - us, err := imdb.GetUserByUserID(req.OpUserID) - if err != nil { - log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.OpUserID) - return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil - } - //to group member - groupMember := db.GroupMember{GroupID: req.GroupID, RoleLevel: constant.GroupOwner, OperatorUserID: req.OpUserID} - utils.CopyStructFields(&groupMember, us) - err = imdb.InsertIntoGroupMember(groupMember) - if err != nil { - log.NewError(req.OperationID, "InsertIntoGroupMember failed ", err.Error(), groupMember) - return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil - } if groupInfo.GroupType != constant.SuperGroup { - addGroupMemberToCacheReq := &pbCache.AddGroupMemberToCacheReq{ - UserIDList: []string{req.OpUserID}, - GroupID: req.GroupID, - OperationID: req.OperationID, + us, err := imdb.GetUserByUserID(req.OpUserID) + if err != nil { + log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), req.OpUserID) + return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil + } + //to group member + groupMember := db.GroupMember{GroupID: req.GroupID, RoleLevel: constant.GroupOwner, OperatorUserID: req.OpUserID} + utils.CopyStructFields(&groupMember, us) + err = imdb.InsertIntoGroupMember(groupMember) + if err != nil { + log.NewError(req.OperationID, "InsertIntoGroupMember failed ", err.Error(), groupMember) + return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID) if etcdConn == nil { @@ -898,20 +920,23 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: constant.ErrInternal.ErrMsg}}, nil } cacheClient := pbCache.NewCacheClient(etcdConn) - cacheResp, err := cacheClient.AddGroupMemberToCache(context.Background(), addGroupMemberToCacheReq) + cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{ + GroupID: req.GroupID, + OperationID: req.OperationID, + }) if err != nil { - log.NewError(req.OperationID, "AddGroupMemberToCache rpc call failed ", err.Error()) + log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error()) return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } if cacheResp.CommonResp.ErrCode != 0 { - log.NewError(req.OperationID, "AddGroupMemberToCache rpc logic call failed ", cacheResp.String()) + log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String()) return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } chat.MemberEnterDirectlyNotification(req.GroupID, req.OpUserID, req.OperationID) log.NewInfo(req.OperationID, "JoinGroup rpc return ") return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil } else { - log.Error(req.OperationID, "JoinGroup rpc failed, group type: ", groupInfo.GroupType) + log.Error(req.OperationID, "JoinGroup rpc failed, group type: ", groupInfo.GroupType, "not support directly") return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrArgs.ErrCode, ErrMsg: constant.ErrArgs.ErrMsg}}, nil } } @@ -926,7 +951,6 @@ func (s *groupServer) JoinGroup(ctx context.Context, req *pbGroup.JoinGroupReq) return &pbGroup.JoinGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } - // //_, err = imdb.GetGroupMemberListByGroupIDAndRoleLevel(req.GroupID, constant.GroupOwner) //if err != nil { // log.NewError(req.OperationID, "GetGroupMemberListByGroupIDAndRoleLevel failed ", err.Error(), req.GroupID, constant.GroupOwner) @@ -994,25 +1018,23 @@ func (s *groupServer) QuitGroup(ctx context.Context, req *pbGroup.QuitGroupReq) } } - reduceGroupMemberFromCacheReq := &pbCache.ReduceGroupMemberFromCacheReq{ - UserIDList: []string{req.OpUserID}, - GroupID: req.GroupID, - OperationID: req.OperationID, - } - etcdConnCache := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID) - if etcdConnCache == nil { + etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID) + if etcdConn == nil { errMsg := req.OperationID + "getcdv3.GetConn == nil" log.NewError(req.OperationID, errMsg) - return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: errMsg}}, nil + return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrInternal.ErrCode, ErrMsg: constant.ErrInternal.ErrMsg}}, nil } - cacheClient := pbCache.NewCacheClient(etcdConnCache) - cacheResp, err := cacheClient.ReduceGroupMemberFromCache(context.Background(), reduceGroupMemberFromCacheReq) + cacheClient := pbCache.NewCacheClient(etcdConn) + cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{ + GroupID: req.GroupID, + OperationID: req.OperationID, + }) if err != nil { - log.NewError(req.OperationID, "ReduceGroupMemberFromCache rpc call failed ", err.Error()) + log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error()) return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } if cacheResp.CommonResp.ErrCode != 0 { - log.NewError(req.OperationID, "ReduceGroupMemberFromCache rpc logic call failed ", cacheResp.String()) + log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String()) return &pbGroup.QuitGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } @@ -1105,6 +1127,11 @@ func (s *groupServer) SetGroupInfo(ctx context.Context, req *pbGroup.SetGroupInf log.NewError(req.OperationID, "SetGroupInfo failed ", err.Error(), groupInfo) return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, http.WrapError(constant.ErrDB) } + if err := rocksCache.DelGroupInfoFromCache(req.GroupInfoForSet.GroupID); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), "DelGroupInfoFromCache failed ", err.Error(), req.GroupInfoForSet.GroupID) + return &pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, http.WrapError(constant.ErrDB) + } + log.NewInfo(req.OperationID, "SetGroupInfo rpc return ", pbGroup.SetGroupInfoResp{CommonResp: &pbGroup.CommonResp{}}) if changedType != 0 { chat.GroupInfoSetNotification(req.OperationID, req.OpUserID, req.GroupInfoForSet.GroupID, groupName, notification, introduction, faceURL, req.GroupInfoForSet.NeedVerification) @@ -1187,8 +1214,10 @@ func (s *groupServer) TransferGroupOwner(_ context.Context, req *pbGroup.Transfe log.NewError(req.OperationID, "UpdateGroupMemberInfo failed ", groupMemberInfo) return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } + if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), req.GroupID, err.Error()) + } chat.GroupOwnerTransferredNotification(req) - return &pbGroup.TransferGroupOwnerResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil } @@ -1379,7 +1408,7 @@ func (s *groupServer) GetGroupMembersCMS(_ context.Context, req *pbGroup.GetGrou return resp, http.WrapError(constant.ErrDB) } log.NewInfo(req.OperationID, groupMembersCount) - resp.MemberNums = groupMembersCount + resp.MemberNums = int32(groupMembersCount) for _, groupMember := range groupMembers { resp.Members = append(resp.Members, &open_im_sdk.GroupMemberFullInfo{ GroupID: req.GroupId, @@ -1443,27 +1472,28 @@ func (s *groupServer) RemoveGroupMembersCMS(_ context.Context, req *pbGroup.Remo } } - reduceGroupMemberFromCacheReq := &pbCache.ReduceGroupMemberFromCacheReq{ - UserIDList: resp.Success, - GroupID: req.GroupId, - OperationID: req.OperationID, - } - etcdConnCache := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID) - if etcdConnCache == nil { + etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID) + if etcdConn == nil { errMsg := req.OperationID + "getcdv3.GetConn == nil" log.NewError(req.OperationID, errMsg) - return resp, http.WrapError(constant.ErrInternal) + return resp, http.WrapError(constant.ErrDB) } - cacheClient := pbCache.NewCacheClient(etcdConnCache) - cacheResp, err := cacheClient.ReduceGroupMemberFromCache(context.Background(), reduceGroupMemberFromCacheReq) + cacheClient := pbCache.NewCacheClient(etcdConn) + cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{ + GroupID: req.GroupId, + OperationID: req.OperationID, + }) if err != nil { - log.NewError(req.OperationID, "ReduceGroupMemberFromCache rpc call failed ", err.Error()) + log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error()) return resp, http.WrapError(constant.ErrDB) } if cacheResp.CommonResp.ErrCode != 0 { - log.NewError(req.OperationID, "ReduceGroupMemberFromCache rpc logic call failed ", cacheResp.String()) + log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String()) return resp, http.WrapError(constant.ErrDB) } + if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupId); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupId) + } chat.MemberKickedNotification(reqKick, resp.Success) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "resp: ", resp) @@ -1504,27 +1534,28 @@ func (s *groupServer) AddGroupMembersCMS(_ context.Context, req *pbGroup.AddGrou } } - addGroupMemberToCacheReq := &pbCache.AddGroupMemberToCacheReq{ - UserIDList: resp.Success, - GroupID: req.GroupId, - OperationID: req.OperationId, - } etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationId) if etcdConn == nil { errMsg := req.OperationId + "getcdv3.GetConn == nil" log.NewError(req.OperationId, errMsg) - return resp, http.WrapError(constant.ErrInternal) + return resp, http.WrapError(constant.ErrDB) } cacheClient := pbCache.NewCacheClient(etcdConn) - cacheResp, err := cacheClient.AddGroupMemberToCache(context.Background(), addGroupMemberToCacheReq) + cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{ + GroupID: req.GroupId, + OperationID: req.OperationId, + }) if err != nil { - log.NewError(req.OperationId, "AddGroupMemberToCache rpc call failed ", err.Error()) + log.NewError(req.OperationId, "DelGroupMemberIDListFromCache rpc call failed ", err.Error()) return resp, http.WrapError(constant.ErrDB) } if cacheResp.CommonResp.ErrCode != 0 { - log.NewError(req.OperationId, "AddGroupMemberToCache rpc logic call failed ", cacheResp.String()) + log.NewError(req.OperationId, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String()) return resp, http.WrapError(constant.ErrDB) } + if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupId); err != nil { + log.NewError(req.OperationId, utils.GetSelfFuncName(), err.Error(), req.GroupId) + } chat.MemberInvitedNotification(req.OperationId, req.GroupId, req.OpUserId, "admin add you to group", resp.Success) return resp, nil @@ -1627,6 +1658,28 @@ func (s *groupServer) DismissGroup(ctx context.Context, req *pbGroup.DismissGrou } } + etcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName, req.OperationID) + if etcdConn == nil { + errMsg := req.OperationID + "getcdv3.GetConn == nil" + log.NewError(req.OperationID, errMsg) + return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 500, ErrMsg: errMsg}}, nil + } + cacheClient := pbCache.NewCacheClient(etcdConn) + cacheResp, err := cacheClient.DelGroupMemberIDListFromCache(context.Background(), &pbCache.DelGroupMemberIDListFromCacheReq{ + GroupID: req.GroupID, + OperationID: req.OperationID, + }) + if err != nil { + log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc call failed ", err.Error()) + return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 500, ErrMsg: err.Error()}}, nil + } + if cacheResp.CommonResp.ErrCode != 0 { + log.NewError(req.OperationID, "DelGroupMemberIDListFromCache rpc logic call failed ", cacheResp.String()) + return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: cacheResp.CommonResp.ErrCode, ErrMsg: cacheResp.CommonResp.ErrMsg}}, nil + } + if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) + } log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}) return &pbGroup.DismissGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil } @@ -1672,6 +1725,9 @@ func (s *groupServer) MuteGroupMember(ctx context.Context, req *pbGroup.MuteGrou log.Error(req.OperationID, "UpdateGroupMemberInfo failed ", err.Error(), groupMemberInfo) return &pbGroup.MuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } + if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) + } chat.GroupMemberMutedNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID, req.MutedSeconds) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}) return &pbGroup.MuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil @@ -1713,6 +1769,9 @@ func (s *groupServer) CancelMuteGroupMember(ctx context.Context, req *pbGroup.Ca log.Error(req.OperationID, "UpdateGroupMemberInfo failed ", err.Error(), groupMemberInfo) return &pbGroup.CancelMuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } + if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) + } chat.GroupMemberCancelMutedNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}) return &pbGroup.CancelMuteGroupMemberResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil @@ -1752,6 +1811,9 @@ func (s *groupServer) MuteGroup(ctx context.Context, req *pbGroup.MuteGroupReq) log.Error(req.OperationID, "OperateGroupStatus failed ", err.Error(), req.GroupID, constant.GroupStatusMuted) return &pbGroup.MuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } + if err := rocksCache.DelGroupInfoFromCache(req.GroupID); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) + } chat.GroupMutedNotification(req.OperationID, req.OpUserID, req.GroupID) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}) return &pbGroup.MuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil @@ -1791,6 +1853,9 @@ func (s *groupServer) CancelMuteGroup(ctx context.Context, req *pbGroup.CancelMu log.Error(req.OperationID, "UpdateGroupInfoDefaultZero failed ", err.Error(), req.GroupID) return &pbGroup.CancelMuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } + if err := rocksCache.DelGroupInfoFromCache(req.GroupID); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) + } chat.GroupCancelMutedNotification(req.OperationID, req.OpUserID, req.GroupID) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}) return &pbGroup.CancelMuteGroupResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil @@ -1803,7 +1868,6 @@ func (s *groupServer) SetGroupMemberNickname(ctx context.Context, req *pbGroup.S log.Error(req.OperationID, errMsg) return &pbGroup.SetGroupMemberNicknameResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrAccess.ErrCode, ErrMsg: constant.ErrAccess.ErrMsg}}, nil } - groupMemberInfo := db.GroupMember{} groupMemberInfo.UserID = req.UserID groupMemberInfo.GroupID = req.GroupID @@ -1824,6 +1888,9 @@ func (s *groupServer) SetGroupMemberNickname(ctx context.Context, req *pbGroup.S log.Error(req.OperationID, errMsg) return &pbGroup.SetGroupMemberNicknameResp{CommonResp: &pbGroup.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: constant.ErrDB.ErrMsg}}, nil } + if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) + } chat.GroupMemberInfoSetNotification(req.OperationID, req.OpUserID, req.GroupID, req.UserID) log.NewInfo(req.OperationID, utils.GetSelfFuncName(), "rpc return ", pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}) return &pbGroup.SetGroupMemberNicknameResp{CommonResp: &pbGroup.CommonResp{ErrCode: 0, ErrMsg: ""}}, nil @@ -1856,6 +1923,9 @@ func (s *groupServer) SetGroupMemberInfo(ctx context.Context, req *pbGroup.SetGr resp.CommonResp.ErrMsg = constant.ErrDB.ErrMsg + ":" + err.Error() return resp, nil } + if err := rocksCache.DelAllGroupMembersInfoFromCache(req.GroupID); err != nil { + log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.GroupID) + } if req.RoleLevel != nil { switch req.RoleLevel.Value { case constant.GroupOrdinaryUsers: diff --git a/internal/rpc/organization/organization.go b/internal/rpc/organization/organization.go index db423caa0..c70cc5c80 100644 --- a/internal/rpc/organization/organization.go +++ b/internal/rpc/organization/organization.go @@ -182,7 +182,7 @@ func (s *organizationServer) UpdateDepartment(ctx context.Context, req *rpc.Upda func (s *organizationServer) GetSubDepartment(ctx context.Context, req *rpc.GetSubDepartmentReq) (*rpc.GetSubDepartmentResp, error) { log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String()) - err, departmentList := imdb.GetSubDepartmentList(req.DepartmentID) + departmentList, err := imdb.GetSubDepartmentList(req.DepartmentID) if err != nil { errMsg := req.OperationID + " " + "GetDepartment failed " + err.Error() log.Error(req.OperationID, errMsg) @@ -477,7 +477,7 @@ func (s *organizationServer) DeleteOrganizationUser(ctx context.Context, req *rp func (s *organizationServer) GetDepartmentMember(ctx context.Context, req *rpc.GetDepartmentMemberReq) (*rpc.GetDepartmentMemberResp, error) { log.NewInfo(req.OperationID, utils.GetSelfFuncName(), " rpc args ", req.String()) - err, departmentMemberList := imdb.GetDepartmentMemberList(req.DepartmentID) + departmentMemberList, err := imdb.GetDepartmentMemberList(req.DepartmentID) if err != nil { errMsg := req.OperationID + " " + req.OpUserID + " is not app manager" log.Error(req.OperationID, errMsg) diff --git a/internal/rpc/user/user.go b/internal/rpc/user/user.go index c774a9c6e..a3f20f993 100644 --- a/internal/rpc/user/user.go +++ b/internal/rpc/user/user.go @@ -6,6 +6,7 @@ import ( "Open_IM/pkg/common/constant" "Open_IM/pkg/common/db" imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "Open_IM/pkg/common/db/rocks_cache" errors "Open_IM/pkg/common/http" "Open_IM/pkg/common/log" "Open_IM/pkg/common/token_verify" @@ -112,7 +113,7 @@ func (s *userServer) GetUserInfo(ctx context.Context, req *pbUser.GetUserInfoReq if len(req.UserIDList) > 0 { for _, userID := range req.UserIDList { var userInfo sdkws.UserInfo - user, err := imdb.GetUserByUserID(userID) + user, err := rocksCache.GetUserInfoFromCache(userID) if err != nil { log.NewError(req.OperationID, "GetUserByUserID failed ", err.Error(), userID) continue @@ -401,36 +402,24 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI CommID: &pbFriend.CommID{OperationID: req.OperationID, FromUserID: req.UserInfo.UserID, OpUserID: req.OpUserID}, } - RpcResp, err := client.GetFriendList(context.Background(), newReq) + rpcResp, err := client.GetFriendList(context.Background(), newReq) if err != nil { log.NewError(req.OperationID, "GetFriendList failed ", err.Error(), newReq) - return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{}}, nil + return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: 500, ErrMsg: err.Error()}}, nil } - for _, v := range RpcResp.FriendInfoList { + for _, v := range rpcResp.FriendInfoList { log.Info(req.OperationID, "UserInfoUpdatedNotification ", req.UserInfo.UserID, v.FriendUser.UserID) chat.UserInfoUpdatedNotification(req.OperationID, req.UserInfo.UserID, v.FriendUser.UserID) } - + if err := rocksCache.DelUserInfoFromCache(user.UserID); err != nil { + log.NewError(req.OperationID, "GetFriendList failed ", err.Error(), newReq) + return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrDB.ErrCode, ErrMsg: err.Error()}}, nil + } chat.UserInfoUpdatedNotification(req.OperationID, req.UserInfo.UserID, req.OpUserID) log.Info(req.OperationID, "UserInfoUpdatedNotification ", req.UserInfo.UserID, req.OpUserID) if req.UserInfo.FaceURL != "" { go s.SyncJoinedGroupMemberFaceURL(req.UserInfo.UserID, req.UserInfo.FaceURL, req.OperationID, req.OpUserID) } - //updateUserInfoToCacheReq := &cache.UpdateUserInfoToCacheReq{ - // OperationID: req.OperationID, - // UserInfoList: []*sdkws.UserInfo{req.UserInfo}, - //} - //cacheEtcdConn := getcdv3.GetConn(config.Config.Etcd.EtcdSchema, strings.Join(config.Config.Etcd.EtcdAddr, ","), config.Config.RpcRegisterName.OpenImCacheName) - //cacheClient := cache.NewCacheClient(cacheEtcdConn) - //resp, err := cacheClient.UpdateUserInfoToCache(context.Background(), updateUserInfoToCacheReq) - //if err != nil { - // log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), updateUserInfoToCacheReq.String()) - // return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrServer.ErrCode, ErrMsg: err.Error()}}, nil - //} - //if resp.CommonResp.ErrCode != 0 { - // log.NewError(req.OperationID, utils.GetSelfFuncName(), resp.String()) - // return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{ErrCode: constant.ErrServer.ErrCode, ErrMsg: resp.CommonResp.ErrMsg}}, nil - //} return &pbUser.UpdateUserInfoResp{CommonResp: &pbUser.CommonResp{}}, nil } func (s *userServer) SetGlobalRecvMessageOpt(ctx context.Context, req *pbUser.SetGlobalRecvMessageOptReq) (*pbUser.SetGlobalRecvMessageOptResp, error) { @@ -456,15 +445,22 @@ func (s *userServer) SetGlobalRecvMessageOpt(ctx context.Context, req *pbUser.Se return &pbUser.SetGlobalRecvMessageOptResp{CommonResp: &pbUser.CommonResp{}}, nil } func (s *userServer) SyncJoinedGroupMemberFaceURL(userID string, faceURL string, operationID string, opUserID string) { - joinedGroupIDList, err := imdb.GetJoinedGroupIDListByUserID(userID) + joinedGroupIDList, err := rocksCache.GetJoinedGroupIDListFromCache(userID) if err != nil { log.NewWarn(operationID, "GetJoinedGroupIDListByUserID failed ", userID, err.Error()) return } - for _, v := range joinedGroupIDList { - groupMemberInfo := db.GroupMember{UserID: userID, GroupID: v, FaceURL: faceURL} - imdb.UpdateGroupMemberInfo(groupMemberInfo) - chat.GroupMemberInfoSetNotification(operationID, opUserID, v, userID) + for _, groupID := range joinedGroupIDList { + groupMemberInfo := db.GroupMember{UserID: userID, GroupID: groupID, FaceURL: faceURL} + if err := imdb.UpdateGroupMemberInfo(groupMemberInfo); err != nil { + log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), groupMemberInfo) + continue + } + if err := rocksCache.DelAllGroupMembersInfoFromCache(groupID); err != nil { + log.NewError(operationID, utils.GetSelfFuncName(), err.Error(), groupID) + continue + } + chat.GroupMemberInfoSetNotification(operationID, opUserID, groupID, userID) } } diff --git a/pkg/common/db/RedisModel.go b/pkg/common/db/RedisModel.go index c96fe08b4..bfeccfd69 100644 --- a/pkg/common/db/RedisModel.go +++ b/pkg/common/db/RedisModel.go @@ -9,7 +9,6 @@ import ( pbCommon "Open_IM/pkg/proto/sdk_ws" "Open_IM/pkg/utils" "context" - "encoding/json" "errors" "fmt" go_redis "github.com/go-redis/redis/v8" @@ -18,6 +17,7 @@ import ( "strconv" "time" ) + const ( accountTempCode = "ACCOUNT_TEMP_CODE" resetPwdTempCode = "RESET_PWD_TEMP_CODE" @@ -27,17 +27,12 @@ const ( uidPidToken = "UID_PID_TOKEN_STATUS:" conversationReceiveMessageOpt = "CON_RECV_MSG_OPT:" getuiToken = "GETUI_TOKEN" - userInfoCache = "USER_INFO_CACHE:" - friendRelationCache = "FRIEND_RELATION_CACHE:" - blackListCache = "BLACK_LIST_CACHE:" - groupCache = "GROUP_CACHE:" messageCache = "MESSAGE_CACHE:" SignalCache = "SIGNAL_CACHE:" SignalListCache = "SIGNAL_LIST_CACHE:" GlobalMsgRecvOpt = "GLOBAL_MSG_RECV_OPT" ) - //func (d * DataBases)pubMessage(channel, msg string) { // d.rdb.Publish(context.Background(),channel,msg) //} @@ -346,84 +341,3 @@ func (d *DataBases) GetGetuiToken() (string, error) { result := d.rdb.Get(context.Background(), getuiToken) return result.String(), result.Err() } - -func (d *DataBases) AddFriendToCache(userID string, friendIDList ...string) error { - var IDList []interface{} - for _, id := range friendIDList { - IDList = append(IDList, id) - } - return d.rdb.SAdd(context.Background(), friendRelationCache+userID, IDList...).Err() -} - -func (d *DataBases) ReduceFriendToCache(userID string, friendIDList ...string) error { - var IDList []interface{} - for _, id := range friendIDList { - IDList = append(IDList, id) - } - return d.rdb.SRem(context.Background(), friendRelationCache+userID, IDList...).Err() -} - -func (d *DataBases) GetFriendIDListFromCache(userID string) ([]string, error) { - result := d.rdb.SMembers(context.Background(), friendRelationCache+userID) - return result.Result() -} - -func (d *DataBases) AddBlackUserToCache(userID string, blackList ...string) error { - var IDList []interface{} - for _, id := range blackList { - IDList = append(IDList, id) - } - return d.rdb.SAdd(context.Background(), blackListCache+userID, IDList...).Err() -} - -func (d *DataBases) ReduceBlackUserFromCache(userID string, blackList ...string) error { - var IDList []interface{} - for _, id := range blackList { - IDList = append(IDList, id) - } - return d.rdb.SRem(context.Background(), blackListCache+userID, IDList...).Err() -} - -func (d *DataBases) GetBlackListFromCache(userID string) ([]string, error) { - result := d.rdb.SMembers(context.Background(), blackListCache+userID) - return result.Result() -} - -func (d *DataBases) AddGroupMemberToCache(groupID string, userIDList ...string) error { - var IDList []interface{} - for _, id := range userIDList { - IDList = append(IDList, id) - } - return d.rdb.SAdd(context.Background(), groupCache+groupID, IDList...).Err() -} - -func (d *DataBases) ReduceGroupMemberFromCache(groupID string, userIDList ...string) error { - var IDList []interface{} - for _, id := range userIDList { - IDList = append(IDList, id) - } - return d.rdb.SRem(context.Background(), groupCache+groupID, IDList...).Err() -} - -func (d *DataBases) GetGroupMemberIDListFromCache(groupID string) ([]string, error) { - result := d.rdb.SMembers(context.Background(), groupCache+groupID) - return result.Result() -} - -func (d *DataBases) SetUserInfoToCache(userID string, m map[string]interface{}) error { - return d.rdb.HSet(context.Background(), userInfoCache+userID, m).Err() -} - -func (d *DataBases) GetUserInfoFromCache(userID string) (*pbCommon.UserInfo, error) { - result, err := d.rdb.HGetAll(context.Background(), userInfoCache+userID).Result() - bytes, err := json.Marshal(result) - if err != nil { - return nil, err - } - userInfo := &pbCommon.UserInfo{} - if err := proto.Unmarshal(bytes, userInfo); err != nil { - return nil, err - } - err = json.Unmarshal(bytes, userInfo) - return userInfo, err -} diff --git a/pkg/common/db/model.go b/pkg/common/db/model.go index f67c0875d..de4461c99 100644 --- a/pkg/common/db/model.go +++ b/pkg/common/db/model.go @@ -37,7 +37,6 @@ type RedisClient struct { client *go_redis.Client cluster *go_redis.ClusterClient go_redis.UniversalClient - enableCluster bool } func key(dbAddress, dbName string) string { @@ -90,16 +89,14 @@ func init() { if err := createMongoIndex(mongoClient, cWorkMoment, true, "work_moment_id"); err != nil { fmt.Println("work_moment_id", "index create failed", err.Error()) } - if err := createMongoIndex(mongoClient, cWorkMoment, false, "user_id", "-create_time"); err != nil { fmt.Println("user_id", "-create_time", "index create failed", err.Error()) } - if err := createMongoIndex(mongoClient, cTag, false, "user_id", "-create_time"); err != nil { fmt.Println("user_id", "-create_time", "index create failed", err.Error()) } if err := createMongoIndex(mongoClient, cTag, true, "tag_id"); err != nil { - fmt.Println("user_id", "-create_time", "index create failed", err.Error()) + fmt.Println("tag_id", "index create failed", err.Error()) } fmt.Println("create index success") DB.mongoClient = mongoClient @@ -145,14 +142,12 @@ func init() { } } - DB.rc = rockscache.NewClient(go_redis.NewClient(&go_redis.Options{ + DB.Rc = rockscache.NewClient(go_redis.NewClient(&go_redis.Options{ Addr: config.Config.Redis.DBAddress[0], Password: config.Config.Redis.DBPassWord, // no password set DB: 0, // use default DB PoolSize: 100, // 连接池大小 }), rockscache.NewDefaultOptions()) - DB.rc.Options.StrongConsistency = true - } func createMongoIndex(client *mongo.Client, collection string, isUnique bool, keys ...string) error { diff --git a/pkg/common/db/mysql.go b/pkg/common/db/mysql.go index 9713537b9..d8370c99a 100644 --- a/pkg/common/db/mysql.go +++ b/pkg/common/db/mysql.go @@ -7,13 +7,13 @@ import ( "sync" "time" - "github.com/jinzhu/gorm" - _ "github.com/jinzhu/gorm/dialects/mysql" + "gorm.io/driver/mysql" + "gorm.io/gorm" ) type mysqlDB struct { sync.RWMutex - dbMap map[string]*gorm.DB + db *gorm.DB } func initMysqlDB() { @@ -22,13 +22,13 @@ func initMysqlDB() { config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], "mysql") var db *gorm.DB var err1 error - db, err := gorm.Open("mysql", dsn) + db, err := gorm.Open(mysql.Open(dsn), nil) if err != nil { fmt.Println("0", "Open failed ", err.Error(), dsn) } if err != nil { time.Sleep(time.Duration(30) * time.Second) - db, err1 = gorm.Open("mysql", dsn) + db, err1 = gorm.Open(mysql.Open(dsn), nil) if err1 != nil { fmt.Println("0", "Open failed ", err1.Error(), dsn) panic(err1.Error()) @@ -42,11 +42,10 @@ func initMysqlDB() { fmt.Println("0", "Exec failed ", err.Error(), sql) panic(err.Error()) } - db.Close() dsn = fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local", config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, config.Config.Mysql.DBAddress[0], config.Config.Mysql.DBDatabaseName) - db, err = gorm.Open("mysql", dsn) + db, err = gorm.Open(mysql.Open(dsn), nil) if err != nil { fmt.Println("0", "Open failed ", err.Error(), dsn) panic(err.Error()) @@ -65,103 +64,70 @@ func initMysqlDB() { db.Set("gorm:table_options", "CHARSET=utf8") db.Set("gorm:table_options", "collation=utf8_unicode_ci") - if !db.HasTable(&Friend{}) { + if !db.Migrator().HasTable(&Friend{}) { fmt.Println("CreateTable Friend") - db.CreateTable(&Friend{}) + db.Migrator().CreateTable(&Friend{}) } - if !db.HasTable(&FriendRequest{}) { + if !db.Migrator().HasTable(&FriendRequest{}) { fmt.Println("CreateTable FriendRequest") - db.CreateTable(&FriendRequest{}) + db.Migrator().CreateTable(&FriendRequest{}) } - if !db.HasTable(&Group{}) { + if !db.Migrator().HasTable(&Group{}) { fmt.Println("CreateTable Group") - db.CreateTable(&Group{}) + db.Migrator().CreateTable(&Group{}) } - if !db.HasTable(&GroupMember{}) { + if !db.Migrator().HasTable(&GroupMember{}) { fmt.Println("CreateTable GroupMember") - db.CreateTable(&GroupMember{}) + db.Migrator().CreateTable(&GroupMember{}) } - if !db.HasTable(&GroupRequest{}) { + if !db.Migrator().HasTable(&GroupRequest{}) { fmt.Println("CreateTable GroupRequest") - db.CreateTable(&GroupRequest{}) + db.Migrator().CreateTable(&GroupRequest{}) } - if !db.HasTable(&User{}) { + if !db.Migrator().HasTable(&User{}) { fmt.Println("CreateTable User") - db.CreateTable(&User{}) + db.Migrator().CreateTable(&User{}) } - if !db.HasTable(&Black{}) { + if !db.Migrator().HasTable(&Black{}) { fmt.Println("CreateTable Black") - db.CreateTable(&Black{}) + db.Migrator().CreateTable(&Black{}) } - if !db.HasTable(&ChatLog{}) { + if !db.Migrator().HasTable(&ChatLog{}) { fmt.Println("CreateTable ChatLog") - db.CreateTable(&ChatLog{}) + db.Migrator().CreateTable(&ChatLog{}) } - if !db.HasTable(&Register{}) { + if !db.Migrator().HasTable(&Register{}) { fmt.Println("CreateTable Register") - db.CreateTable(&Register{}) + db.Migrator().CreateTable(&Register{}) } - if !db.HasTable(&Conversation{}) { + if !db.Migrator().HasTable(&Conversation{}) { fmt.Println("CreateTable Conversation") - db.CreateTable(&Conversation{}) + db.Migrator().CreateTable(&Conversation{}) } - if !db.HasTable(&Department{}) { + if !db.Migrator().HasTable(&Department{}) { fmt.Println("CreateTable Department") - db.CreateTable(&Department{}) + db.Migrator().CreateTable(&Department{}) } - if !db.HasTable(&OrganizationUser{}) { + if !db.Migrator().HasTable(&OrganizationUser{}) { fmt.Println("CreateTable OrganizationUser") - db.CreateTable(&OrganizationUser{}) + db.Migrator().CreateTable(&OrganizationUser{}) } - if !db.HasTable(&DepartmentMember{}) { + if !db.Migrator().HasTable(&DepartmentMember{}) { fmt.Println("CreateTable DepartmentMember") - db.CreateTable(&DepartmentMember{}) + db.Migrator().CreateTable(&DepartmentMember{}) } - if !db.HasTable(&AppVersion{}) { + if !db.Migrator().HasTable(&AppVersion{}) { fmt.Println("CreateTable DepartmentMember") - db.CreateTable(&AppVersion{}) + db.Migrator().CreateTable(&AppVersion{}) } + DB.MysqlDB.db = db return } -func (m *mysqlDB) DefaultGormDB() (*gorm.DB, error) { - return m.GormDB(config.Config.Mysql.DBAddress[0], config.Config.Mysql.DBDatabaseName) -} - -func (m *mysqlDB) GormDB(dbAddress, dbName string) (*gorm.DB, error) { - m.Lock() - defer m.Unlock() - - k := key(dbAddress, dbName) - if _, ok := m.dbMap[k]; !ok { - if err := m.open(dbAddress, dbName); err != nil { - return nil, err - } - } - return m.dbMap[k], nil -} - -func (m *mysqlDB) open(dbAddress, dbName string) error { - dsn := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=true&loc=Local", - config.Config.Mysql.DBUserName, config.Config.Mysql.DBPassword, dbAddress, dbName) - db, err := gorm.Open("mysql", dsn) - if err != nil { - return err - } - - db.SingularTable(true) - db.DB().SetMaxOpenConns(config.Config.Mysql.DBMaxOpenConns) - db.DB().SetMaxIdleConns(config.Config.Mysql.DBMaxIdleConns) - db.DB().SetConnMaxLifetime(time.Duration(config.Config.Mysql.DBMaxLifeTime) * time.Second) - - if m.dbMap == nil { - m.dbMap = make(map[string]*gorm.DB) - } - k := key(dbAddress, dbName) - m.dbMap[k] = db - return nil +func (m *mysqlDB) DefaultGormDB() *gorm.DB { + return DB.MysqlDB.db } diff --git a/pkg/common/db/mysql_model/im_mysql_model/conversation_model.go b/pkg/common/db/mysql_model/im_mysql_model/conversation_model.go index 0af86c57d..5588ba912 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/conversation_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/conversation_model.go @@ -7,99 +7,65 @@ import ( ) func SetConversation(conversation db.Conversation) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } - dbConn.LogMode(false) newConversation := conversation - if dbConn.Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 { + if db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 { log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create") - return dbConn.Model(&db.Conversation{}).Create(conversation).Error + return db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(conversation).Error // if exist, then update record } else { log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "exist in db, update") //force update - return dbConn.Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID). - Update(map[string]interface{}{"recv_msg_opt": conversation.RecvMsgOpt, "is_pinned": conversation.IsPinned, "is_private_chat": conversation.IsPrivateChat, + return db.DB.MysqlDB.DefaultGormDB().Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID). + Updates(map[string]interface{}{"recv_msg_opt": conversation.RecvMsgOpt, "is_pinned": conversation.IsPinned, "is_private_chat": conversation.IsPrivateChat, "group_at_type": conversation.GroupAtType, "is_not_in_group": conversation.IsNotInGroup}).Error } } func SetOneConversation(conversation db.Conversation) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } - dbConn.LogMode(false) - return dbConn.Model(&db.Conversation{}).Create(conversation).Error + return db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(conversation).Error } func PeerUserSetConversation(conversation db.Conversation) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } - dbConn.LogMode(false) newConversation := conversation - if dbConn.Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 { + if db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 { log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create") - return dbConn.Model(&db.Conversation{}).Create(conversation).Error + return db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(conversation).Error // if exist, then update record } log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "exist in db, update") //force update - return dbConn.Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID). - Update(map[string]interface{}{"is_private_chat": conversation.IsPrivateChat}).Error + return db.DB.MysqlDB.DefaultGormDB().Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID). + Updates(map[string]interface{}{"is_private_chat": conversation.IsPrivateChat}).Error } func SetRecvMsgOpt(conversation db.Conversation) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } - dbConn.LogMode(false) newConversation := conversation - if dbConn.Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 { + if db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Find(&newConversation).RowsAffected == 0 { log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "not exist in db, create") - return dbConn.Model(&db.Conversation{}).Create(conversation).Error + return db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Create(conversation).Error // if exist, then update record } else { log.NewDebug("", utils.GetSelfFuncName(), "conversation", conversation, "exist in db, update") //force update - return dbConn.Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID). - Update(map[string]interface{}{"recv_msg_opt": conversation.RecvMsgOpt}).Error + return db.DB.MysqlDB.DefaultGormDB().Model(conversation).Where("owner_user_id = ? and conversation_id = ?", conversation.OwnerUserID, conversation.ConversationID). + Updates(map[string]interface{}{"recv_msg_opt": conversation.RecvMsgOpt}).Error } } func GetUserAllConversations(ownerUserID string) ([]db.Conversation, error) { var conversations []db.Conversation - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return conversations, err - } - dbConn.LogMode(false) - err = dbConn.Model(&db.Conversation{}).Where("owner_user_id=?", ownerUserID).Find(&conversations).Error + err := db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Where("owner_user_id=?", ownerUserID).Find(&conversations).Error return conversations, err } func GetMultipleUserConversationByConversationID(ownerUserIDList []string, conversationID string) ([]db.Conversation, error) { var conversations []db.Conversation - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return conversations, err - } - dbConn.LogMode(false) - err = dbConn.Model(&db.Conversation{}).Where("owner_user_id IN ? and conversation_id=?", ownerUserIDList, conversationID).Find(&conversations).Error + err := db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Where("owner_user_id IN ? and conversation_id=?", ownerUserIDList, conversationID).Find(&conversations).Error return conversations, err } func GetExistConversationUserIDList(ownerUserIDList []string, conversationID string) ([]string, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return nil, err - } var resultArr []string - err = dbConn.Table("conversations").Where(" owner_user_id IN (?) and conversation_id=?", ownerUserIDList, conversationID).Pluck("owner_user_id", &resultArr).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("conversations").Where(" owner_user_id IN (?) and conversation_id=?", ownerUserIDList, conversationID).Pluck("owner_user_id", &resultArr).Error if err != nil { return nil, err } @@ -108,38 +74,21 @@ func GetExistConversationUserIDList(ownerUserIDList []string, conversationID str func GetConversation(OwnerUserID, conversationID string) (db.Conversation, error) { var conversation db.Conversation - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return conversation, err - } - err = dbConn.Table("conversations").Where("owner_user_id=? and conversation_id=?", OwnerUserID, conversationID).Take(&conversation).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("conversations").Where("owner_user_id=? and conversation_id=?", OwnerUserID, conversationID).Take(&conversation).Error return conversation, err } func GetConversations(OwnerUserID string, conversationIDs []string) ([]db.Conversation, error) { var conversations []db.Conversation - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return conversations, err - } - err = dbConn.Model(&db.Conversation{}).Where("conversation_id IN (?) and owner_user_id=?", conversationIDs, OwnerUserID).Find(&conversations).Error + err := db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Where("conversation_id IN (?) and owner_user_id=?", conversationIDs, OwnerUserID).Find(&conversations).Error return conversations, err } func GetConversationsByConversationIDMultipleOwner(OwnerUserIDList []string, conversationID string) ([]db.Conversation, error) { var conversations []db.Conversation - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return conversations, err - } - err = dbConn.Model(&db.Conversation{}).Where("owner_user_id IN (?) and conversation_id=?", OwnerUserIDList, conversationID).Find(&conversations).Error + err := db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Where("owner_user_id IN (?) and conversation_id=?", OwnerUserIDList, conversationID).Find(&conversations).Error return conversations, err } func UpdateColumnsConversations(ownerUserIDList []string, conversationID string, args map[string]interface{}) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } - dbConn.LogMode(false) - return dbConn.Debug().Model(&db.Conversation{}).Where("owner_user_id IN (?) and conversation_id=?", ownerUserIDList, conversationID).Updates(args).Error + return db.DB.MysqlDB.DefaultGormDB().Model(&db.Conversation{}).Where("owner_user_id IN (?) and conversation_id=?", ownerUserIDList, conversationID).Updates(args).Error } diff --git a/pkg/common/db/mysql_model/im_mysql_model/demo_model.go b/pkg/common/db/mysql_model/im_mysql_model/demo_model.go index fcfc2705f..8668026d7 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/demo_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/demo_model.go @@ -2,16 +2,12 @@ package im_mysql_model import ( "Open_IM/pkg/common/db" - _ "github.com/jinzhu/gorm" + _ "gorm.io/gorm" ) func GetRegister(account, areaCode, userID string) (*db.Register, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return nil, err - } var r db.Register - return &r, dbConn.Table("registers").Where("user_id = ? and user_id != ? or account = ? or account =? and area_code=?", + return &r, db.DB.MysqlDB.DefaultGormDB().Table("registers").Where("user_id = ? and user_id != ? or account = ? or account =? and area_code=?", userID, "", account, account, areaCode).Take(&r).Error } @@ -23,21 +19,12 @@ func SetPassword(account, password, ex, userID, areaCode string) error { UserID: userID, AreaCode: areaCode, } - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } - return dbConn.Table("registers").Create(&r).Error + return db.DB.MysqlDB.DefaultGormDB().Table("registers").Create(&r).Error } func ResetPassword(account, password string) error { r := db.Register{ Password: password, } - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - dbConn.LogMode(false) - if err != nil { - return err - } - return dbConn.Table("registers").Where("account = ?", account).Update(&r).Error + return db.DB.MysqlDB.DefaultGormDB().Table("registers").Where("account = ?", account).Updates(&r).Error } diff --git a/pkg/common/db/mysql_model/im_mysql_model/file_model.go b/pkg/common/db/mysql_model/im_mysql_model/file_model.go index c8ab188aa..959bb6cf1 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/file_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/file_model.go @@ -6,10 +6,6 @@ import ( ) func UpdateAppVersion(appType int, version string, forceUpdate bool, fileName, yamlName, updateLog string) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } updateTime := int(time.Now().Unix()) app := db.AppVersion{ Version: version, @@ -20,24 +16,19 @@ func UpdateAppVersion(appType int, version string, forceUpdate bool, fileName, y ForceUpdate: forceUpdate, UpdateLog: updateLog, } - result := dbConn.Model(db.AppVersion{}).Where("type = ?", appType).Update(map[string]interface{}{"force_update": forceUpdate, + result := db.DB.MysqlDB.DefaultGormDB().Model(db.AppVersion{}).Where("type = ?", appType).Updates(map[string]interface{}{"force_update": forceUpdate, "version": version, "update_time": int(time.Now().Unix()), "file_name": fileName, "yaml_name": yamlName, "type": appType, "update_log": updateLog}) if result.Error != nil { return result.Error } if result.RowsAffected == 0 { - err := dbConn.Create(&app).Error + err := db.DB.MysqlDB.DefaultGormDB().Create(&app).Error return err } return nil } func GetNewestVersion(appType int) (*db.AppVersion, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() app := db.AppVersion{} - if err != nil { - return &app, err - } - dbConn.LogMode(true) - return &app, dbConn.Model(db.AppVersion{}).First(&app, appType).Error + return &app, db.DB.MysqlDB.DefaultGormDB().Model(db.AppVersion{}).First(&app, appType).Error } diff --git a/pkg/common/db/mysql_model/im_mysql_model/friend_model.go b/pkg/common/db/mysql_model/im_mysql_model/friend_model.go index 600da2f79..33e22771d 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/friend_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/friend_model.go @@ -7,13 +7,8 @@ import ( ) func InsertToFriend(toInsertFollow *db.Friend) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } toInsertFollow.CreateTime = time.Now() - - err = dbConn.Table("friends").Create(toInsertFollow).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("friends").Create(toInsertFollow).Error if err != nil { return err } @@ -21,12 +16,8 @@ func InsertToFriend(toInsertFollow *db.Friend) error { } func GetFriendRelationshipFromFriend(OwnerUserID, FriendUserID string) (*db.Friend, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return nil, err - } var friend db.Friend - err = dbConn.Table("friends").Where("owner_user_id=? and friend_user_id=?", OwnerUserID, FriendUserID).Take(&friend).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("friends").Where("owner_user_id=? and friend_user_id=?", OwnerUserID, FriendUserID).Take(&friend).Error if err != nil { return nil, err } @@ -34,15 +25,10 @@ func GetFriendRelationshipFromFriend(OwnerUserID, FriendUserID string) (*db.Frie } func GetFriendListByUserID(OwnerUserID string) ([]db.Friend, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return nil, err - } var friends []db.Friend var x db.Friend x.OwnerUserID = OwnerUserID - err = dbConn.Table("friends").Where("owner_user_id=?", OwnerUserID).Find(&friends).Error - + err := db.DB.MysqlDB.DefaultGormDB().Table("friends").Where("owner_user_id=?", OwnerUserID).Find(&friends).Error if err != nil { return nil, err } @@ -50,12 +36,8 @@ func GetFriendListByUserID(OwnerUserID string) ([]db.Friend, error) { } func GetFriendIDListByUserID(OwnerUserID string) ([]string, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return nil, err - } var friendIDList []string - err = dbConn.Table("friends").Where("owner_user_id=?", OwnerUserID).Pluck("friend_user_id", &friendIDList).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("friends").Where("owner_user_id=?", OwnerUserID).Pluck("friend_user_id", &friendIDList).Error if err != nil { return nil, err } @@ -63,29 +45,9 @@ func GetFriendIDListByUserID(OwnerUserID string) ([]string, error) { } func UpdateFriendComment(OwnerUserID, FriendUserID, Remark string) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } - err = dbConn.Exec("update friends set remark=? where owner_user_id=? and friend_user_id=?", Remark, OwnerUserID, FriendUserID).Error - return err + return db.DB.MysqlDB.DefaultGormDB().Exec("update friends set remark=? where owner_user_id=? and friend_user_id=?", Remark, OwnerUserID, FriendUserID).Error } func DeleteSingleFriendInfo(OwnerUserID, FriendUserID string) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } - err = dbConn.Table("friends").Where("owner_user_id=? and friend_user_id=?", OwnerUserID, FriendUserID).Delete(db.Friend{}).Error - return err + return db.DB.MysqlDB.DefaultGormDB().Table("friends").Where("owner_user_id=? and friend_user_id=?", OwnerUserID, FriendUserID).Delete(db.Friend{}).Error } - -//type Friend struct { -// OwnerUserID string `gorm:"column:owner_user_id;primaryKey;"` -// FriendUserID string `gorm:"column:friend_user_id;primaryKey;"` -// Remark string `gorm:"column:remark"` -// CreateTime time.Time `gorm:"column:create_time"` -// AddSource int32 `gorm:"column:add_source"` -// OperatorUserID string `gorm:"column:operator_user_id"` -// Ex string `gorm:"column:ex"` -//} diff --git a/pkg/common/db/mysql_model/im_mysql_model/friend_request_model.go b/pkg/common/db/mysql_model/im_mysql_model/friend_request_model.go index 171a6aedf..633f605e1 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/friend_request_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/friend_request_model.go @@ -20,12 +20,8 @@ import ( // who apply to add me func GetReceivedFriendsApplicationListByUserID(ToUserID string) ([]db.FriendRequest, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return nil, err - } var usersInfo []db.FriendRequest - err = dbConn.Table("friend_requests").Where("to_user_id=?", ToUserID).Find(&usersInfo).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Where("to_user_id=?", ToUserID).Find(&usersInfo).Error if err != nil { return nil, err } @@ -34,12 +30,8 @@ func GetReceivedFriendsApplicationListByUserID(ToUserID string) ([]db.FriendRequ //I apply to add somebody func GetSendFriendApplicationListByUserID(FromUserID string) ([]db.FriendRequest, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return nil, err - } var usersInfo []db.FriendRequest - err = dbConn.Table("friend_requests").Where("from_user_id=?", FromUserID).Find(&usersInfo).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Where("from_user_id=?", FromUserID).Find(&usersInfo).Error if err != nil { return nil, err } @@ -48,12 +40,8 @@ func GetSendFriendApplicationListByUserID(FromUserID string) ([]db.FriendRequest //FromUserId apply to add ToUserID func GetFriendApplicationByBothUserID(FromUserID, ToUserID string) (*db.FriendRequest, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return nil, err - } var friendRequest db.FriendRequest - err = dbConn.Table("friend_requests").Where("from_user_id=? and to_user_id=?", FromUserID, ToUserID).Take(&friendRequest).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Where("from_user_id=? and to_user_id=?", FromUserID, ToUserID).Take(&friendRequest).Error if err != nil { return nil, err } @@ -61,23 +49,13 @@ func GetFriendApplicationByBothUserID(FromUserID, ToUserID string) (*db.FriendRe } func UpdateFriendApplication(friendRequest *db.FriendRequest) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } friendRequest.CreateTime = time.Now() - - return dbConn.Table("friend_requests").Where("from_user_id=? and to_user_id=?", - friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest).Error + return db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Where("from_user_id=? and to_user_id=?", + friendRequest.FromUserID, friendRequest.ToUserID).Updates(&friendRequest).Error } func InsertFriendApplication(friendRequest *db.FriendRequest, args map[string]interface{}) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } - - if err = dbConn.Table("friend_requests").Create(friendRequest).Error; err == nil { + if err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Create(friendRequest).Error; err == nil { return nil } @@ -89,7 +67,7 @@ func InsertFriendApplication(friendRequest *db.FriendRequest, args map[string]in friendRequest.CreateTime = time.Now() args["create_time"] = friendRequest.CreateTime - u := dbConn.Model(friendRequest).Updates(args) + u := db.DB.MysqlDB.DefaultGormDB().Model(friendRequest).Updates(args) //u := dbConn.Table("friend_requests").Where("from_user_id=? and to_user_id=?", // friendRequest.FromUserID, friendRequest.ToUserID).Update(&friendRequest) //u := dbConn.Table("friend_requests").Where("from_user_id=? and to_user_id=?", @@ -104,7 +82,7 @@ func InsertFriendApplication(friendRequest *db.FriendRequest, args map[string]in if friendRequest.HandleTime.Unix() < 0 { friendRequest.HandleTime = utils.UnixSecondToTime(0) } - err = dbConn.Table("friend_requests").Create(friendRequest).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("friend_requests").Create(friendRequest).Error if err != nil { return err } diff --git a/pkg/common/db/mysql_model/im_mysql_model/group_member_model.go b/pkg/common/db/mysql_model/im_mysql_model/group_member_model.go index 83a59e6d9..306e8eaeb 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/group_member_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/group_member_model.go @@ -22,16 +22,12 @@ import ( //} func InsertIntoGroupMember(toInsertInfo db.GroupMember) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } toInsertInfo.JoinTime = time.Now() if toInsertInfo.RoleLevel == 0 { toInsertInfo.RoleLevel = constant.GroupOrdinaryUsers } toInsertInfo.MuteEndTime = time.Unix(int64(time.Now().Second()), 0) - err = dbConn.Table("group_members").Create(toInsertInfo).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Create(toInsertInfo).Error if err != nil { return err } @@ -39,12 +35,8 @@ func InsertIntoGroupMember(toInsertInfo db.GroupMember) error { } func GetGroupMemberListByUserID(userID string) ([]db.GroupMember, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return nil, err - } var groupMemberList []db.GroupMember - err = dbConn.Table("group_members").Where("user_id=?", userID).Find(&groupMemberList).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("user_id=?", userID).Find(&groupMemberList).Error //err = dbConn.Table("group_members").Where("user_id=?", userID).Take(&groupMemberList).Error if err != nil { return nil, err @@ -53,13 +45,8 @@ func GetGroupMemberListByUserID(userID string) ([]db.GroupMember, error) { } func GetGroupMemberListByGroupID(groupID string) ([]db.GroupMember, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return nil, err - } var groupMemberList []db.GroupMember - err = dbConn.Table("group_members").Where("group_id=?", groupID).Find(&groupMemberList).Error - + err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupID).Find(&groupMemberList).Error if err != nil { return nil, err } @@ -67,13 +54,8 @@ func GetGroupMemberListByGroupID(groupID string) ([]db.GroupMember, error) { } func GetGroupMemberIDListByGroupID(groupID string) ([]string, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return nil, err - } - dbConn.LogMode(false) var groupMemberIDList []string - err = dbConn.Table("group_members").Where("group_id=?", groupID).Pluck("user_id", &groupMemberIDList).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupID).Pluck("user_id", &groupMemberIDList).Error if err != nil { return nil, err } @@ -81,12 +63,8 @@ func GetGroupMemberIDListByGroupID(groupID string) ([]string, error) { } func GetGroupMemberListByGroupIDAndRoleLevel(groupID string, roleLevel int32) ([]db.GroupMember, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return nil, err - } var groupMemberList []db.GroupMember - err = dbConn.Table("group_members").Where("group_id=? and role_level=?", groupID, roleLevel).Find(&groupMemberList).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and role_level=?", groupID, roleLevel).Find(&groupMemberList).Error if err != nil { return nil, err } @@ -94,12 +72,8 @@ func GetGroupMemberListByGroupIDAndRoleLevel(groupID string, roleLevel int32) ([ } func GetGroupMemberInfoByGroupIDAndUserID(groupID, userID string) (*db.GroupMember, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return nil, err - } var groupMember db.GroupMember - err = dbConn.Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Limit(1).Take(&groupMember).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Limit(1).Take(&groupMember).Error if err != nil { return nil, err } @@ -107,73 +81,33 @@ func GetGroupMemberInfoByGroupIDAndUserID(groupID, userID string) (*db.GroupMemb } func DeleteGroupMemberByGroupIDAndUserID(groupID, userID string) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } - err = dbConn.Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Delete(db.GroupMember{}).Error - if err != nil { - return err - } - return nil + return db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and user_id=? ", groupID, userID).Delete(db.GroupMember{}).Error } func DeleteGroupMemberByGroupID(groupID string) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } - err = dbConn.Table("group_members").Where("group_id=? ", groupID).Delete(db.GroupMember{}).Error - if err != nil { - return err - } - return nil + return db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? ", groupID).Delete(db.GroupMember{}).Error } func UpdateGroupMemberInfo(groupMemberInfo db.GroupMember) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } - err = dbConn.Table("group_members").Where("group_id=? and user_id=?", groupMemberInfo.GroupID, groupMemberInfo.UserID).Update(&groupMemberInfo).Error - if err != nil { - return err - } - return nil + return db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and user_id=?", groupMemberInfo.GroupID, groupMemberInfo.UserID).Updates(&groupMemberInfo).Error } func UpdateGroupMemberInfoByMap(groupMemberInfo db.GroupMember, m map[string]interface{}) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } - err = dbConn.Table("group_members").Where("group_id=? and user_id=?", groupMemberInfo.GroupID, groupMemberInfo.UserID).Updates(m).Error - if err != nil { - return err - } - return nil + return db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and user_id=?", groupMemberInfo.GroupID, groupMemberInfo.UserID).Updates(m).Error } func GetOwnerManagerByGroupID(groupID string) ([]db.GroupMember, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return nil, err - } var groupMemberList []db.GroupMember - err = dbConn.Table("group_members").Where("group_id=? and role_level>?", groupID, constant.GroupOrdinaryUsers).Find(&groupMemberList).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=? and role_level>?", groupID, constant.GroupOrdinaryUsers).Find(&groupMemberList).Error if err != nil { return nil, err } return groupMemberList, nil } -func GetGroupMemberNumByGroupID(groupID string) (uint32, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return 0, utils.Wrap(err, "DefaultGormDB failed") - } - var number uint32 - err = dbConn.Table("group_members").Where("group_id=?", groupID).Count(&number).Error +func GetGroupMemberNumByGroupID(groupID string) (int64, error) { + var number int64 + err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupID).Count(&number).Error if err != nil { return 0, utils.Wrap(err, "") } @@ -195,12 +129,8 @@ func GetGroupOwnerInfoByGroupID(groupID string) (*db.GroupMember, error) { } func IsExistGroupMember(groupID, userID string) bool { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return false - } - var number int32 - err = dbConn.Table("group_members").Where("group_id = ? and user_id = ?", groupID, userID).Count(&number).Error + var number int64 + err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id = ? and user_id = ?", groupID, userID).Count(&number).Error if err != nil { return false } @@ -270,36 +200,23 @@ func IsGroupOwnerAdmin(groupID, UserID string) bool { func GetGroupMembersByGroupIdCMS(groupId string, userName string, showNumber, pageNumber int32) ([]db.GroupMember, error) { var groupMembers []db.GroupMember - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return groupMembers, err - } - err = dbConn.Table("group_members").Where("group_id=?", groupId).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&groupMembers).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupId).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&groupMembers).Error if err != nil { return nil, err } return groupMembers, nil } -func GetGroupMembersCount(groupId, userName string) (int32, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - var count int32 - if err != nil { - return count, err - } - dbConn.LogMode(false) - if err := dbConn.Table("group_members").Where("group_id=?", groupId).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Count(&count).Error; err != nil { +func GetGroupMembersCount(groupId, userName string) (int64, error) { + var count int64 + if err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupId).Where(fmt.Sprintf(" nickname like '%%%s%%' ", userName)).Count(&count).Error; err != nil { return count, err } return count, nil } func UpdateGroupMemberInfoDefaultZero(groupMemberInfo db.GroupMember, args map[string]interface{}) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } - return dbConn.Model(groupMemberInfo).Updates(args).Error + return db.DB.MysqlDB.DefaultGormDB().Model(groupMemberInfo).Updates(args).Error } // diff --git a/pkg/common/db/mysql_model/im_mysql_model/group_model.go b/pkg/common/db/mysql_model/im_mysql_model/group_model.go index 954683a6f..aa70f24b6 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/group_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/group_model.go @@ -3,10 +3,9 @@ package im_mysql_model import ( "Open_IM/pkg/common/constant" "Open_IM/pkg/common/db" - "Open_IM/pkg/utils" "errors" "fmt" - "github.com/jinzhu/gorm" + "gorm.io/gorm" "time" ) @@ -24,15 +23,11 @@ import ( //} func InsertIntoGroup(groupInfo db.Group) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } if groupInfo.GroupName == "" { groupInfo.GroupName = "Group Chat" } groupInfo.CreateTime = time.Now() - err = dbConn.Table("groups").Create(groupInfo).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Create(groupInfo).Error if err != nil { return err } @@ -40,12 +35,8 @@ func InsertIntoGroup(groupInfo db.Group) error { } func GetGroupInfoByGroupID(groupId string) (*db.Group, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return nil, utils.Wrap(err, "") - } var groupInfo db.Group - err = dbConn.Table("groups").Where("group_id=?", groupId).Take(&groupInfo).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id=?", groupId).Take(&groupInfo).Error if err != nil { return nil, err } @@ -53,33 +44,18 @@ func GetGroupInfoByGroupID(groupId string) (*db.Group, error) { } func SetGroupInfo(groupInfo db.Group) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } - err = dbConn.Table("groups").Where("group_id=?", groupInfo.GroupID).Update(&groupInfo).Error - return err + return db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id=?", groupInfo.GroupID).Updates(&groupInfo).Error } func GetGroupsByName(groupName string, pageNumber, showNumber int32) ([]db.Group, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() var groups []db.Group - if err != nil { - return groups, err - } - - err = dbConn.Table("groups").Where(fmt.Sprintf(" name like '%%%s%%' ", groupName)).Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&groups).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where(fmt.Sprintf(" name like '%%%s%%' ", groupName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&groups).Error return groups, err } func GetGroups(pageNumber, showNumber int) ([]db.Group, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() var groups []db.Group - if err != nil { - return groups, err - } - - if err = dbConn.Table("groups").Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&groups).Error; err != nil { + if err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&groups).Error; err != nil { return groups, err } return groups, nil @@ -97,27 +73,18 @@ func OperateGroupStatus(groupId string, groupStatus int32) error { } func DeleteGroup(groupId string) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } - var group db.Group var groupMembers []db.GroupMember - if err := dbConn.Table("groups").Where("group_id=?", groupId).Delete(&group).Error; err != nil { + if err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id=?", groupId).Delete(&group).Error; err != nil { return err } - if err := dbConn.Table("group_members").Where("group_id=?", groupId).Delete(groupMembers).Error; err != nil { + if err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id=?", groupId).Delete(groupMembers).Error; err != nil { return err } return nil } func OperateGroupRole(userId, groupId string, roleLevel int32) (string, string, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return "", "", err - } groupMember := db.GroupMember{ UserID: userId, GroupID: groupId, @@ -126,10 +93,11 @@ func OperateGroupRole(userId, groupId string, roleLevel int32) (string, string, RoleLevel: roleLevel, } groupMaster := db.GroupMember{} + var err error switch roleLevel { case constant.GroupOwner: - err = dbConn.Transaction(func(tx *gorm.DB) error { - result := dbConn.Table("group_members").Where("group_id = ? and role_level = ?", groupId, constant.GroupOwner).First(&groupMaster).Update(&db.GroupMember{ + err = db.DB.MysqlDB.DefaultGormDB().Transaction(func(tx *gorm.DB) error { + result := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id = ? and role_level = ?", groupId, constant.GroupOwner).First(&groupMaster).Updates(&db.GroupMember{ RoleLevel: constant.GroupOrdinaryUsers, }) if result.Error != nil { @@ -139,7 +107,7 @@ func OperateGroupRole(userId, groupId string, roleLevel int32) (string, string, return errors.New(fmt.Sprintf("user %s not exist in group %s or already operate", userId, groupId)) } - result = dbConn.Table("group_members").First(&groupMember).Update(updateInfo) + result = db.DB.MysqlDB.DefaultGormDB().Table("group_members").First(&groupMember).Updates(updateInfo) if result.Error != nil { return result.Error } @@ -150,8 +118,8 @@ func OperateGroupRole(userId, groupId string, roleLevel int32) (string, string, }) case constant.GroupOrdinaryUsers: - err = dbConn.Transaction(func(tx *gorm.DB) error { - result := dbConn.Table("group_members").Where("group_id = ? and role_level = ?", groupId, constant.GroupOwner).First(&groupMaster) + err = db.DB.MysqlDB.DefaultGormDB().Transaction(func(tx *gorm.DB) error { + result := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("group_id = ? and role_level = ?", groupId, constant.GroupOwner).First(&groupMaster) if result.Error != nil { return result.Error } @@ -161,7 +129,7 @@ func OperateGroupRole(userId, groupId string, roleLevel int32) (string, string, if groupMaster.UserID == userId { return errors.New(fmt.Sprintf("user %s is master of %s, cant set to ordinary user", userId, groupId)) } else { - result = dbConn.Table("group_members").Find(&groupMember).Update(updateInfo) + result = db.DB.MysqlDB.DefaultGormDB().Table("group_members").Find(&groupMember).Updates(updateInfo) if result.Error != nil { return result.Error } @@ -172,64 +140,41 @@ func OperateGroupRole(userId, groupId string, roleLevel int32) (string, string, return nil }) } - return "", "", nil + return "", "", err } func GetGroupsCountNum(group db.Group) (int32, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return 0, err - } - - var count int32 - if err := dbConn.Table("groups").Where(fmt.Sprintf(" name like '%%%s%%' ", group.GroupName)).Count(&count).Error; err != nil { + var count int64 + if err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where(fmt.Sprintf(" name like '%%%s%%' ", group.GroupName)).Count(&count).Error; err != nil { return 0, err } - return count, nil + return int32(count), nil } func GetGroupById(groupId string) (db.Group, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() group := db.Group{ GroupID: groupId, } - if err != nil { - return group, err - } - - if err := dbConn.Table("groups").Find(&group).Error; err != nil { + if err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Find(&group).Error; err != nil { return group, err } return group, nil } func GetGroupMaster(groupId string) (db.GroupMember, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() groupMember := db.GroupMember{} - if err != nil { - return groupMember, err - } - - if err := dbConn.Table("group_members").Where("role_level=? and group_id=?", constant.GroupOwner, groupId).Find(&groupMember).Error; err != nil { + if err := db.DB.MysqlDB.DefaultGormDB().Table("group_members").Where("role_level=? and group_id=?", constant.GroupOwner, groupId).Find(&groupMember).Error; err != nil { return groupMember, err } return groupMember, nil } func UpdateGroupInfoDefaultZero(groupID string, args map[string]interface{}) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } - return dbConn.Table("groups").Where("group_id = ? ", groupID).Update(args).Error + return db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id = ? ", groupID).Updates(args).Error } func GetAllGroupIDList() ([]string, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return nil, err - } var groupIDList []string - err = dbConn.Table("groups").Pluck("group_id", &groupIDList).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Pluck("group_id", &groupIDList).Error return groupIDList, err } diff --git a/pkg/common/db/mysql_model/im_mysql_model/group_request_model.go b/pkg/common/db/mysql_model/im_mysql_model/group_request_model.go index 5e27cc3d2..a9dd6d98e 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/group_request_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/group_request_model.go @@ -20,27 +20,18 @@ import ( //} func UpdateGroupRequest(groupRequest db.GroupRequest) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } if groupRequest.HandledTime.Unix() < 0 { groupRequest.HandledTime = utils.UnixSecondToTime(0) } - return dbConn.Table("group_requests").Where("group_id=? and user_id=?", groupRequest.GroupID, groupRequest.UserID).Update(&groupRequest).Error + return db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", groupRequest.GroupID, groupRequest.UserID).Updates(&groupRequest).Error } func InsertIntoGroupRequest(toInsertInfo db.GroupRequest) error { DelGroupRequestByGroupIDAndUserID(toInsertInfo.GroupID, toInsertInfo.UserID) - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } - if toInsertInfo.HandledTime.Unix() < 0 { toInsertInfo.HandledTime = utils.UnixSecondToTime(0) } - u := dbConn.Table("group_requests").Where("group_id=? and user_id=?", toInsertInfo.GroupID, toInsertInfo.UserID).Update(&toInsertInfo) + u := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", toInsertInfo.GroupID, toInsertInfo.UserID).Updates(&toInsertInfo) if u.RowsAffected != 0 { return nil } @@ -50,7 +41,7 @@ func InsertIntoGroupRequest(toInsertInfo db.GroupRequest) error { toInsertInfo.HandledTime = utils.UnixSecondToTime(0) } - err = dbConn.Table("group_requests").Create(&toInsertInfo).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Create(&toInsertInfo).Error if err != nil { return err } @@ -58,12 +49,8 @@ func InsertIntoGroupRequest(toInsertInfo db.GroupRequest) error { } func GetGroupRequestByGroupIDAndUserID(groupID, userID string) (*db.GroupRequest, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return nil, err - } var groupRequest db.GroupRequest - err = dbConn.Table("group_requests").Where("user_id=? and group_id=?", userID, groupID).Take(&groupRequest).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("user_id=? and group_id=?", userID, groupID).Take(&groupRequest).Error if err != nil { return nil, err } @@ -71,24 +58,12 @@ func GetGroupRequestByGroupIDAndUserID(groupID, userID string) (*db.GroupRequest } func DelGroupRequestByGroupIDAndUserID(groupID, userID string) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } - err = dbConn.Table("group_requests").Where("group_id=? and user_id=?", groupID, userID).Delete(db.GroupRequest{}).Error - if err != nil { - return err - } - return nil + return db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=? and user_id=?", groupID, userID).Delete(db.GroupRequest{}).Error } func GetGroupRequestByGroupID(groupID string) ([]db.GroupRequest, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return nil, err - } var groupRequestList []db.GroupRequest - err = dbConn.Table("group_requests").Where("group_id=?", groupID).Find(&groupRequestList).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("group_id=?", groupID).Find(&groupRequestList).Error if err != nil { return nil, err } @@ -119,12 +94,7 @@ func GetGroupApplicationList(userID string) ([]db.GroupRequest, error) { func GetUserReqGroupByUserID(userID string) ([]db.GroupRequest, error) { var groupRequestList []db.GroupRequest - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return nil, err - } - dbConn.LogMode(false) - err = dbConn.Table("group_requests").Where("user_id=?", userID).Find(&groupRequestList).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("group_requests").Where("user_id=?", userID).Find(&groupRequestList).Error return groupRequestList, err } diff --git a/pkg/common/db/mysql_model/im_mysql_model/message_cms.go b/pkg/common/db/mysql_model/im_mysql_model/message_cms.go index 29fb650cf..1279aad80 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/message_cms.go +++ b/pkg/common/db/mysql_model/im_mysql_model/message_cms.go @@ -8,15 +8,10 @@ import ( ) func GetChatLog(chatLog db.ChatLog, pageNumber, showNumber int32) ([]db.ChatLog, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() var chatLogs []db.ChatLog - if err != nil { - return chatLogs, err - } - dbConn.LogMode(false) - db := dbConn.Table("chat_logs"). + db := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs"). Where(fmt.Sprintf(" content like '%%%s%%'", chatLog.Content)). - Limit(showNumber).Offset(showNumber * (pageNumber - 1)) + Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))) if chatLog.SessionType != 0 { db = db.Where("session_type = ?", chatLog.SessionType) } @@ -32,19 +27,14 @@ func GetChatLog(chatLog db.ChatLog, pageNumber, showNumber int32) ([]db.ChatLog, if chatLog.SendTime.Unix() > 0 { db = db.Where("send_time > ? and send_time < ?", chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1)) } - err = db.Find(&chatLogs).Error + err := db.Find(&chatLogs).Error return chatLogs, err } func GetChatLogCount(chatLog db.ChatLog) (int64, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() var chatLogs []db.ChatLog var count int64 - if err != nil { - return count, err - } - dbConn.LogMode(false) - db := dbConn.Table("chat_logs"). + db := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs"). Where(fmt.Sprintf(" content like '%%%s%%'", chatLog.Content)) if chatLog.SessionType != 0 { db = db.Where("session_type = ?", chatLog.SessionType) @@ -63,6 +53,6 @@ func GetChatLogCount(chatLog db.ChatLog) (int64, error) { db = db.Where("send_time > ? and send_time < ?", chatLog.SendTime, chatLog.SendTime.AddDate(0, 0, 1)) } - err = db.Find(&chatLogs).Count(&count).Error + err := db.Find(&chatLogs).Count(&count).Error return count, err } diff --git a/pkg/common/db/mysql_model/im_mysql_model/organization_model.go b/pkg/common/db/mysql_model/im_mysql_model/organization_model.go index 6ac231032..221bb4831 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/organization_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/organization_model.go @@ -3,175 +3,116 @@ package im_mysql_model import ( "Open_IM/pkg/common/db" "Open_IM/pkg/utils" - "github.com/jinzhu/gorm" + "gorm.io/gorm" "time" ) func CreateDepartment(department *db.Department) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } department.CreateTime = time.Now() - return dbConn.Table("departments").Create(department).Error + return db.DB.MysqlDB.DefaultGormDB().Table("departments").Create(department).Error } func GetDepartment(departmentID string) (*db.Department, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return nil, err - } var department db.Department - err = dbConn.Table("departments").Where("department_id=?", departmentID).Find(&department).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("department_id=?", departmentID).Find(&department).Error return &department, err } func UpdateDepartment(department *db.Department, args map[string]interface{}) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } - if err = dbConn.Table("departments").Where("department_id=?", department.DepartmentID).Updates(department).Error; err != nil { + if err := db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("department_id=?", department.DepartmentID).Updates(department).Error; err != nil { return err } if args != nil { - return dbConn.Table("departments").Where("department_id=?", department.DepartmentID).Updates(args).Error + return db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("department_id=?", department.DepartmentID).Updates(args).Error } return nil } -func GetSubDepartmentList(departmentID string) (error, []db.Department) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err, nil - } +func GetSubDepartmentList(departmentID string) ([]db.Department, error) { var departmentList []db.Department + var err error if departmentID == "-1" { - err = dbConn.Table("departments").Find(&departmentList).Error + err = db.DB.MysqlDB.DefaultGormDB().Table("departments").Find(&departmentList).Error } else { - err = dbConn.Table("departments").Where("parent_id=?", departmentID).Find(&departmentList).Error + err = db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("parent_id=?", departmentID).Find(&departmentList).Error } - return err, departmentList + return departmentList, err } func DeleteDepartment(departmentID string) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { + var err error + if err = db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("department_id=?", departmentID).Delete(db.Department{}).Error; err != nil { return err } - if err = dbConn.Table("departments").Where("department_id=?", departmentID).Delete(db.Department{}).Error; err != nil { - return err - } - if err = dbConn.Table("department_members").Where("department_id=?", departmentID).Delete(db.DepartmentMember{}).Error; err != nil { + if err = db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=?", departmentID).Delete(db.DepartmentMember{}).Error; err != nil { return err } return nil } func CreateOrganizationUser(organizationUser *db.OrganizationUser) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } organizationUser.CreateTime = time.Now() - - return dbConn.Table("organization_users").Create(organizationUser).Error + return db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Create(organizationUser).Error } func GetOrganizationUser(userID string) (error, *db.OrganizationUser) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err, nil - } organizationUser := db.OrganizationUser{} - err = dbConn.Table("organization_users").Where("user_id=?", userID).Take(&organizationUser).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Where("user_id=?", userID).Take(&organizationUser).Error return err, &organizationUser } func UpdateOrganizationUser(organizationUser *db.OrganizationUser, args map[string]interface{}) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } - if err = dbConn.Table("organization_users").Where("user_id=?", organizationUser.UserID).Updates(organizationUser).Error; err != nil { + if err := db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Where("user_id=?", organizationUser.UserID).Updates(organizationUser).Error; err != nil { return err } if args != nil { - return dbConn.Table("organization_users").Where("user_id=?", organizationUser.UserID).Updates(args).Error + return db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Where("user_id=?", organizationUser.UserID).Updates(args).Error } return nil } func CreateDepartmentMember(departmentMember *db.DepartmentMember) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } departmentMember.CreateTime = time.Now() - return dbConn.Table("department_members").Create(departmentMember).Error + return db.DB.MysqlDB.DefaultGormDB().Table("department_members").Create(departmentMember).Error } func GetUserInDepartment(userID string) (error, []db.DepartmentMember) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err, nil - } var departmentMemberList []db.DepartmentMember - err = dbConn.Table("department_members").Where("user_id=?", userID).Find(&departmentMemberList).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("user_id=?", userID).Find(&departmentMemberList).Error return err, departmentMemberList } func UpdateUserInDepartment(departmentMember *db.DepartmentMember, args map[string]interface{}) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } - if err = dbConn.Table("department_members").Where("department_id=? AND user_id=?", departmentMember.DepartmentID, departmentMember.UserID). + if err := db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=? AND user_id=?", departmentMember.DepartmentID, departmentMember.UserID). Updates(departmentMember).Error; err != nil { return err } if args != nil { - return dbConn.Table("department_members").Where("department_id=? AND user_id=?", departmentMember.DepartmentID, departmentMember.UserID). + return db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=? AND user_id=?", departmentMember.DepartmentID, departmentMember.UserID). Updates(args).Error } return nil } func DeleteUserInDepartment(departmentID, userID string) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } - return dbConn.Table("department_members").Where("department_id=? AND user_id=?", departmentID, userID).Delete(db.DepartmentMember{}).Error + return db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=? AND user_id=?", departmentID, userID).Delete(db.DepartmentMember{}).Error } func DeleteUserInAllDepartment(userID string) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } - return dbConn.Table("department_members").Where("user_id=?", userID).Delete(db.DepartmentMember{}).Error + return db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("user_id=?", userID).Delete(db.DepartmentMember{}).Error } func DeleteOrganizationUser(OrganizationUserID string) error { if err := DeleteUserInAllDepartment(OrganizationUserID); err != nil { return err } - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } - return dbConn.Table("organization_users").Where("user_id=?", OrganizationUserID).Delete(db.OrganizationUser{}).Error + return db.DB.MysqlDB.DefaultGormDB().Table("organization_users").Where("user_id=?", OrganizationUserID).Delete(db.OrganizationUser{}).Error } func GetDepartmentMemberUserIDList(departmentID string) (error, []string) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err, nil - } var departmentMemberList []db.DepartmentMember - err = dbConn.Table("department_members").Where("department_id=?", departmentID).Take(&departmentMemberList).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=?", departmentID).Take(&departmentMemberList).Error if err != nil { return err, nil } @@ -182,77 +123,54 @@ func GetDepartmentMemberUserIDList(departmentID string) (error, []string) { return err, userIDList } -func GetDepartmentMemberList(departmentID string) (error, []db.DepartmentMember) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err, nil - } +func GetDepartmentMemberList(departmentID string) ([]db.DepartmentMember, error) { var departmentMemberList []db.DepartmentMember + var err error if departmentID == "-1" { - err = dbConn.Table("department_members").Find(&departmentMemberList).Error + err = db.DB.MysqlDB.DefaultGormDB().Table("department_members").Find(&departmentMemberList).Error } else { - err = dbConn.Table("department_members").Where("department_id=?", departmentID).Find(&departmentMemberList).Error + err = db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=?", departmentID).Find(&departmentMemberList).Error } if err != nil { - return err, nil + return nil, err } - return err, departmentMemberList + return departmentMemberList, err } func GetAllOrganizationUserID() (error, []string) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err, nil - } var OrganizationUser db.OrganizationUser var result []string - return dbConn.Model(&OrganizationUser).Pluck("user_id", &result).Error, result + return db.DB.MysqlDB.DefaultGormDB().Model(&OrganizationUser).Pluck("user_id", &result).Error, result } func GetDepartmentMemberNum(departmentID string) (error, uint32) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return utils.Wrap(err, "DefaultGormDB failed"), 0 - } - var number uint32 - err = dbConn.Table("department_members").Where("department_id=?", departmentID).Count(&number).Error + var number int64 + err := db.DB.MysqlDB.DefaultGormDB().Table("department_members").Where("department_id=?", departmentID).Count(&number).Error if err != nil { return utils.Wrap(err, ""), 0 } - return nil, number + return nil, uint32(number) } func GetSubDepartmentNum(departmentID string) (error, uint32) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return utils.Wrap(err, "DefaultGormDB failed"), 0 - } - var number uint32 - err = dbConn.Table("departments").Where("parent_id=?", departmentID).Count(&number).Error + var number int64 + err := db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("parent_id=?", departmentID).Count(&number).Error if err != nil { return utils.Wrap(err, ""), 0 } - return nil, number + return nil, uint32(number) } func SetDepartmentRelatedGroupID(groupID, departmentID string) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return utils.Wrap(err, "DefaultGormDB failed") - } department := &db.Department{RelatedGroupID: groupID} - return dbConn.Model(&department).Where("department_id=?", departmentID).Update(department).Error + return db.DB.MysqlDB.DefaultGormDB().Model(&department).Where("department_id=?", departmentID).Updates(department).Error } func GetDepartmentRelatedGroupIDList(departmentIDList []string) ([]string, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return nil, utils.Wrap(err, "DefaultGormDB failed") - } var groupIDList []string - err = dbConn.Table("departments").Where("department_id IN (?) ", departmentIDList).Pluck("related_group_id", &groupIDList).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("departments").Where("department_id IN (?) ", departmentIDList).Pluck("related_group_id", &groupIDList).Error return groupIDList, err } @@ -260,8 +178,7 @@ func getDepartmentParent(departmentID string, dbConn *gorm.DB) (*db.Department, var department db.Department var parentDepartment db.Department //var parentID string - dbConn.LogMode(true) - err := dbConn.Model(&department).Where("department_id=?", departmentID).Select("parent_id").First(&department).Error + err := db.DB.MysqlDB.DefaultGormDB().Model(&department).Where("department_id=?", departmentID).Select("parent_id").First(&department).Error if err != nil { return nil, utils.Wrap(err, "") } @@ -287,21 +204,14 @@ func GetDepartmentParent(departmentID string, dbConn *gorm.DB, parentIDList *[]s } func GetDepartmentParentIDList(departmentID string) ([]string, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return nil, err - } + dbConn := db.DB.MysqlDB.DefaultGormDB() var parentIDList []string - err = GetDepartmentParent(departmentID, dbConn, &parentIDList) + err := GetDepartmentParent(departmentID, dbConn, &parentIDList) return parentIDList, err } func GetRandomDepartmentID() (string, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return "", err - } department := &db.Department{} - err = dbConn.Model(department).Order("RAND()").Where("related_group_id != ? AND department_id != ? AND department_type = ?", "", "0", 1).First(department).Error + err := db.DB.MysqlDB.DefaultGormDB().Model(department).Order("RAND()").Where("related_group_id != ? AND department_id != ? AND department_type = ?", "", "0", 1).First(department).Error return department.DepartmentID, err } diff --git a/pkg/common/db/mysql_model/im_mysql_model/statistics_model.go b/pkg/common/db/mysql_model/im_mysql_model/statistics_model.go index aa07c1688..b8d3e9d17 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/statistics_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/statistics_model.go @@ -6,102 +6,57 @@ import ( ) func GetActiveUserNum(from, to time.Time) (int32, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return 0, err - } - dbConn.LogMode(false) - var num int32 - err = dbConn.Table("chat_logs").Select("count(distinct(send_id))").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error - return num, err + var num int64 + err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Select("count(distinct(send_id))").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error + return int32(num), err } func GetIncreaseUserNum(from, to time.Time) (int32, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return 0, err - } - dbConn.LogMode(false) - var num int32 - err = dbConn.Table("users").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error - return num, err + var num int64 + err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error + return int32(num), err } func GetTotalUserNum() (int32, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return 0, err - } - dbConn.LogMode(false) - var num int32 - err = dbConn.Table("users").Count(&num).Error - return num, err + var num int64 + err := db.DB.MysqlDB.DefaultGormDB().Table("users").Count(&num).Error + return int32(num), err } func GetTotalUserNumByDate(to time.Time) (int32, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return 0, err - } - dbConn.LogMode(false) - var num int32 - err = dbConn.Table("users").Where("create_time <= ?", to).Count(&num).Error - return num, err + var num int64 + err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("create_time <= ?", to).Count(&num).Error + return int32(num), err } func GetPrivateMessageNum(from, to time.Time) (int32, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return 0, err - } - dbConn.LogMode(false) - var num int32 - err = dbConn.Table("chat_logs").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 1).Count(&num).Error - return num, err + var num int64 + err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 1).Count(&num).Error + return int32(num), err } func GetGroupMessageNum(from, to time.Time) (int32, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return 0, err - } - dbConn.LogMode(false) - var num int32 - err = dbConn.Table("chat_logs").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 2).Count(&num).Error - return num, err + var num int64 + err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 2).Count(&num).Error + return int32(num), err } func GetIncreaseGroupNum(from, to time.Time) (int32, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return 0, err - } - dbConn.LogMode(false) - var num int32 - err = dbConn.Table("groups").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error - return num, err + var num int64 + err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("create_time >= ? and create_time <= ?", from, to).Count(&num).Error + return int32(num), err } func GetTotalGroupNum() (int32, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return 0, err - } - dbConn.LogMode(false) - var num int32 - err = dbConn.Table("groups").Count(&num).Error - return num, err + var num int64 + err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Count(&num).Error + return int32(num), err } func GetGroupNum(to time.Time) (int32, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return 0, err - } - dbConn.LogMode(false) - var num int32 - err = dbConn.Table("groups").Where("create_time <= ?", to).Count(&num).Error - return num, err + var num int64 + err := db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("create_time <= ?", to).Count(&num).Error + return int32(num), err } type activeGroup struct { @@ -111,18 +66,13 @@ type activeGroup struct { } func GetActiveGroups(from, to time.Time, limit int) ([]*activeGroup, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() var activeGroups []*activeGroup - if err != nil { - return activeGroups, err - } - dbConn.LogMode(false) - err = dbConn.Table("chat_logs").Select("recv_id, count(*) as message_num").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 2).Group("recv_id").Limit(limit).Order("message_num DESC").Find(&activeGroups).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Select("recv_id, count(*) as message_num").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 2).Group("recv_id").Limit(limit).Order("message_num DESC").Find(&activeGroups).Error for _, activeGroup := range activeGroups { group := db.Group{ GroupID: activeGroup.Id, } - dbConn.Table("groups").Where("group_id= ? ", group.GroupID).Find(&group) + db.DB.MysqlDB.DefaultGormDB().Table("groups").Where("group_id= ? ", group.GroupID).Find(&group) activeGroup.Name = group.GroupName } return activeGroups, err @@ -135,18 +85,13 @@ type activeUser struct { } func GetActiveUsers(from, to time.Time, limit int) ([]*activeUser, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() var activeUsers []*activeUser - if err != nil { - return activeUsers, err - } - dbConn.LogMode(false) - err = dbConn.Table("chat_logs").Select("send_id, count(*) as message_num").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 1).Group("send_id").Limit(limit).Order("message_num DESC").Find(&activeUsers).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Select("send_id, count(*) as message_num").Where("create_time >= ? and create_time <= ? and session_type = ?", from, to, 1).Group("send_id").Limit(limit).Order("message_num DESC").Find(&activeUsers).Error for _, activeUser := range activeUsers { user := db.User{ UserID: activeUser.Id, } - dbConn.Table("users").Select("user_id, name").Find(&user) + db.DB.MysqlDB.DefaultGormDB().Table("users").Select("user_id, name").Find(&user) activeUser.Name = user.Nickname } return activeUsers, err diff --git a/pkg/common/db/mysql_model/im_mysql_model/user_black_list_model.go b/pkg/common/db/mysql_model/im_mysql_model/user_black_list_model.go index 3cdbdea96..b4bfc1038 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/user_black_list_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/user_black_list_model.go @@ -7,13 +7,8 @@ import ( ) func InsertInToUserBlackList(black db.Black) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } black.CreateTime = time.Now() - err = dbConn.Table("blacks").Create(black).Error - return err + return db.DB.MysqlDB.DefaultGormDB().Table("blacks").Create(black).Error } //type Black struct { @@ -26,31 +21,18 @@ func InsertInToUserBlackList(black db.Black) error { //} func CheckBlack(ownerUserID, blockUserID string) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } var black db.Black - err = dbConn.Table("blacks").Where("owner_user_id=? and block_user_id=?", ownerUserID, blockUserID).Find(&black).Error - return err + return db.DB.MysqlDB.DefaultGormDB().Table("blacks").Where("owner_user_id=? and block_user_id=?", ownerUserID, blockUserID).Find(&black).Error } func RemoveBlackList(ownerUserID, blockUserID string) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } - err = dbConn.Table("blacks").Where("owner_user_id=? and block_user_id=?", ownerUserID, blockUserID).Delete(db.Black{}).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("blacks").Where("owner_user_id=? and block_user_id=?", ownerUserID, blockUserID).Delete(db.Black{}).Error return utils.Wrap(err, "RemoveBlackList failed") } func GetBlackListByUserID(ownerUserID string) ([]db.Black, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return nil, err - } var blackListUsersInfo []db.Black - err = dbConn.Table("blacks").Where("owner_user_id=?", ownerUserID).Find(&blackListUsersInfo).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("blacks").Where("owner_user_id=?", ownerUserID).Find(&blackListUsersInfo).Error if err != nil { return nil, err } @@ -58,12 +40,8 @@ func GetBlackListByUserID(ownerUserID string) ([]db.Black, error) { } func GetBlackIDListByUserID(ownerUserID string) ([]string, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return nil, err - } var blackIDList []string - err = dbConn.Table("blacks").Where("owner_user_id=?", ownerUserID).Pluck("block_user_id", &blackIDList).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("blacks").Where("owner_user_id=?", ownerUserID).Pluck("block_user_id", &blackIDList).Error if err != nil { return nil, err } diff --git a/pkg/common/db/mysql_model/im_mysql_model/user_model.go b/pkg/common/db/mysql_model/im_mysql_model/user_model.go index 1598bac4e..ddc4a93cf 100644 --- a/pkg/common/db/mysql_model/im_mysql_model/user_model.go +++ b/pkg/common/db/mysql_model/im_mysql_model/user_model.go @@ -7,8 +7,6 @@ import ( "Open_IM/pkg/utils" "fmt" "time" - - _ "github.com/jinzhu/gorm/dialects/mysql" ) func init() { @@ -37,10 +35,6 @@ func init() { } func UserRegister(user db.User) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } user.CreateTime = time.Now() if user.AppMangerLevel == 0 { user.AppMangerLevel = constant.AppOrdinaryUsers @@ -48,7 +42,7 @@ func UserRegister(user db.User) error { if user.Birth.Unix() < 0 { user.Birth = utils.UnixSecondToTime(0) } - err = dbConn.Table("users").Create(&user).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("users").Create(&user).Error if err != nil { return err } @@ -56,31 +50,19 @@ func UserRegister(user db.User) error { } func DeleteUser(userID string) (i int64) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return 0 - } - i = dbConn.Table("users").Where("user_id=?", userID).Delete(db.User{}).RowsAffected + i = db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", userID).Delete(db.User{}).RowsAffected return i } func GetAllUser() ([]db.User, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return nil, err - } var userList []db.User - err = dbConn.Table("users").Find(&userList).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("users").Find(&userList).Error return userList, err } func GetUserByUserID(userID string) (*db.User, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return nil, err - } var user db.User - err = dbConn.Table("users").Where("user_id=?", userID).Take(&user).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", userID).Take(&user).Error if err != nil { return nil, err } @@ -88,12 +70,8 @@ func GetUserByUserID(userID string) (*db.User, error) { } func GetUserNameByUserID(userID string) (string, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return "", err - } var user db.User - err = dbConn.Table("users").Select("name").Where("user_id=?", userID).First(&user).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("users").Select("name").Where("user_id=?", userID).First(&user).Error if err != nil { return "", err } @@ -101,33 +79,17 @@ func GetUserNameByUserID(userID string) (string, error) { } func UpdateUserInfo(user db.User) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } - dbConn.LogMode(false) - err = dbConn.Table("users").Where("user_id=?", user.UserID).Update(&user).Error - - return err + return db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", user.UserID).Updates(&user).Error } func UpdateUserInfoByMap(user db.User, m map[string]interface{}) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } - dbConn.LogMode(false) - err = dbConn.Table("users").Where("user_id=?", user.UserID).Updates(m).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", user.UserID).Updates(m).Error return err } func SelectAllUserID() ([]string, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return nil, err - } var resultArr []string - err = dbConn.Table("users").Pluck("user_id", &resultArr).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("users").Pluck("user_id", &resultArr).Error if err != nil { return nil, err } @@ -135,14 +97,8 @@ func SelectAllUserID() ([]string, error) { } func SelectSomeUserID(userIDList []string) ([]string, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - dbConn.LogMode(false) - if err != nil { - return nil, err - } var resultArr []string - err = dbConn.Table("users").Where("user_id IN (?) ", userIDList).Pluck("user_id", &resultArr).Error - + err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id IN (?) ", userIDList).Pluck("user_id", &resultArr).Error if err != nil { return nil, err } @@ -150,13 +106,8 @@ func SelectSomeUserID(userIDList []string) ([]string, error) { } func GetUsers(showNumber, pageNumber int32) ([]db.User, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() var users []db.User - if err != nil { - return users, err - } - dbConn.LogMode(false) - err = dbConn.Table("users").Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&users).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("users").Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&users).Error if err != nil { return users, err } @@ -164,10 +115,6 @@ func GetUsers(showNumber, pageNumber int32) ([]db.User, error) { } func AddUser(userId, phoneNumber, name string) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } user := db.User{ PhoneNumber: phoneNumber, Birth: time.Now(), @@ -175,17 +122,13 @@ func AddUser(userId, phoneNumber, name string) error { UserID: userId, Nickname: name, } - result := dbConn.Table("users").Create(&user) + result := db.DB.MysqlDB.DefaultGormDB().Table("users").Create(&user) return result.Error } func UserIsBlock(userId string) (bool, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return false, err - } var user db.BlackList - rows := dbConn.Table("black_lists").Where("uid=?", userId).First(&user).RowsAffected + rows := db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid=?", userId).First(&user).RowsAffected if rows >= 1 { return true, nil } @@ -197,10 +140,6 @@ func BlockUser(userId, endDisableTime string) error { if err != nil || user.UserID == "" { return err } - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } end, err := time.Parse("2006-01-02 15:04:05", endDisableTime) if err != nil { return err @@ -209,9 +148,9 @@ func BlockUser(userId, endDisableTime string) error { return constant.ErrDB } var blockUser db.BlackList - dbConn.Table("black_lists").Where("uid=?", userId).First(&blockUser) + db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid=?", userId).First(&blockUser) if blockUser.UserId != "" { - dbConn.Model(&blockUser).Where("uid=?", blockUser.UserId).Update("end_disable_time", end) + db.DB.MysqlDB.DefaultGormDB().Model(&blockUser).Where("uid=?", blockUser.UserId).Update("end_disable_time", end) return nil } blockUser = db.BlackList{ @@ -219,18 +158,12 @@ func BlockUser(userId, endDisableTime string) error { BeginDisableTime: time.Now(), EndDisableTime: end, } - result := dbConn.Create(&blockUser) + result := db.DB.MysqlDB.DefaultGormDB().Create(&blockUser) return result.Error } func UnBlockUser(userId string) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } - dbConn.LogMode(false) - result := dbConn.Where("uid=?", userId).Delete(&db.BlackList{}) - return result.Error + return db.DB.MysqlDB.DefaultGormDB().Where("uid=?", userId).Delete(&db.BlackList{}).Error } type BlockUserInfo struct { @@ -240,21 +173,17 @@ type BlockUserInfo struct { } func GetBlockUserById(userId string) (BlockUserInfo, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() var blockUserInfo BlockUserInfo blockUser := db.BlackList{ UserId: userId, } - if err != nil { - return blockUserInfo, err - } - if err = dbConn.Table("black_lists").Where("uid=?", userId).Find(&blockUser).Error; err != nil { + if err := db.DB.MysqlDB.DefaultGormDB().Table("black_lists").Where("uid=?", userId).Find(&blockUser).Error; err != nil { return blockUserInfo, err } user := db.User{ UserID: blockUser.UserId, } - if err := dbConn.Find(&user).Error; err != nil { + if err := db.DB.MysqlDB.DefaultGormDB().Find(&user).Error; err != nil { return blockUserInfo, err } blockUserInfo.User.UserID = user.UserID @@ -266,19 +195,14 @@ func GetBlockUserById(userId string) (BlockUserInfo, error) { } func GetBlockUsers(showNumber, pageNumber int32) ([]BlockUserInfo, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() var blockUserInfos []BlockUserInfo var blockUsers []db.BlackList - if err != nil { - return blockUserInfos, err - } - dbConn.LogMode(false) - if err = dbConn.Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&blockUsers).Error; err != nil { + if err := db.DB.MysqlDB.DefaultGormDB().Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&blockUsers).Error; err != nil { return blockUserInfos, err } for _, blockUser := range blockUsers { var user db.User - if err := dbConn.Table("users").Where("user_id=?", blockUser.UserId).First(&user).Error; err == nil { + if err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where("user_id=?", blockUser.UserId).First(&user).Error; err == nil { blockUserInfos = append(blockUserInfos, BlockUserInfo{ User: db.User{ UserID: user.UserID, @@ -294,38 +218,23 @@ func GetBlockUsers(showNumber, pageNumber int32) ([]BlockUserInfo, error) { } func GetUserByName(userName string, showNumber, pageNumber int32) ([]db.User, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() var users []db.User - if err != nil { - return users, err - } - dbConn.LogMode(false) - err = dbConn.Table("users").Where(fmt.Sprintf(" name like '%%%s%%' ", userName)).Limit(showNumber).Offset(showNumber * (pageNumber - 1)).Find(&users).Error + err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where(fmt.Sprintf(" name like '%%%s%%' ", userName)).Limit(int(showNumber)).Offset(int(showNumber * (pageNumber - 1))).Find(&users).Error return users, err } func GetUsersCount(user db.User) (int32, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return 0, err - } - dbConn.LogMode(false) - var count int32 - if err := dbConn.Table("users").Where(fmt.Sprintf(" name like '%%%s%%' ", user.Nickname)).Count(&count).Error; err != nil { + var count int64 + if err := db.DB.MysqlDB.DefaultGormDB().Table("users").Where(fmt.Sprintf(" name like '%%%s%%' ", user.Nickname)).Count(&count).Error; err != nil { return 0, err } - return count, nil + return int32(count), nil } func GetBlockUsersNumCount() (int32, error) { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return 0, err - } - dbConn.LogMode(false) - var count int32 - if err := dbConn.Model(&db.BlackList{}).Count(&count).Error; err != nil { + var count int64 + if err := db.DB.MysqlDB.DefaultGormDB().Model(&db.BlackList{}).Count(&count).Error; err != nil { return 0, err } - return count, nil + return int32(count), nil } diff --git a/pkg/common/db/mysql_model/im_mysql_msg_model/chat_log_model.go b/pkg/common/db/mysql_model/im_mysql_msg_model/chat_log_model.go index 5f7ef59f7..77841198c 100644 --- a/pkg/common/db/mysql_model/im_mysql_msg_model/chat_log_model.go +++ b/pkg/common/db/mysql_model/im_mysql_msg_model/chat_log_model.go @@ -19,10 +19,6 @@ import ( ) func InsertMessageToChatLog(msg pbMsg.MsgDataToMQ) error { - dbConn, err := db.DB.MysqlDB.DefaultGormDB() - if err != nil { - return err - } chatLog := new(db.ChatLog) copier.Copy(chatLog, msg.MsgData) switch msg.MsgData.SessionType { @@ -47,5 +43,5 @@ func InsertMessageToChatLog(msg pbMsg.MsgDataToMQ) error { chatLog.CreateTime = utils.UnixMillSecondToTime(msg.MsgData.CreateTime) chatLog.SendTime = utils.UnixMillSecondToTime(msg.MsgData.SendTime) log.NewDebug("test", "this is ", chatLog) - return dbConn.Table("chat_logs").Create(chatLog).Error + return db.DB.MysqlDB.DefaultGormDB().Table("chat_logs").Create(chatLog).Error } diff --git a/pkg/common/db/mysql_model/im_mysql_msg_model/hash_code.go b/pkg/common/db/mysql_model/im_mysql_msg_model/hash_code.go index a631462ce..2c3e81932 100644 --- a/pkg/common/db/mysql_model/im_mysql_msg_model/hash_code.go +++ b/pkg/common/db/mysql_model/im_mysql_msg_model/hash_code.go @@ -2,9 +2,7 @@ package im_mysql_msg_model import ( "Open_IM/pkg/common/config" - "Open_IM/pkg/common/db" "hash/crc32" - "strconv" ) func getHashMsgDBAddr(userID string) string { @@ -16,21 +14,3 @@ func getHashMsgTableIndex(userID string) int { hCode := crc32.ChecksumIEEE([]byte(userID)) return int(hCode % uint32(config.Config.Mysql.DBMsgTableNum)) } - -func QueryUserMsgID(userID string) ([]string, error) { - dbAddress, dbTableIndex := getHashMsgDBAddr(userID), getHashMsgTableIndex(userID) - dbTableName := "receive" + strconv.Itoa(dbTableIndex) - - dbConn, _ := db.DB.MysqlDB.GormDB(dbAddress, config.Config.Mysql.DBTableName) - - var msgID string - var msgIDList []string - rows, _ := dbConn.Raw("select msg_id from ? where user_id = ?", dbTableName, userID).Rows() - defer rows.Close() - for rows.Next() { - rows.Scan(&msgID) - msgIDList = append(msgIDList, msgID) - } - - return msgIDList, nil -} diff --git a/pkg/common/db/rocks_cache/rocks_cache.go b/pkg/common/db/rocks_cache/rocks_cache.go new file mode 100644 index 000000000..73d35bde5 --- /dev/null +++ b/pkg/common/db/rocks_cache/rocks_cache.go @@ -0,0 +1,248 @@ +package rocksCache + +import ( + "Open_IM/pkg/common/db" + imdb "Open_IM/pkg/common/db/mysql_model/im_mysql_model" + "encoding/json" + "strings" + "time" +) + +const ( + userInfoCache = "USER_INFO_CACHE:" + friendRelationCache = "FRIEND_RELATION_CACHE:" + blackListCache = "BLACK_LIST_CACHE:" + groupCache = "GROUP_CACHE:" + groupInfoCache = "GROUP_INFO_CACHE:" + groupOwnerIDCache = "GROUP_OWNER_ID:" + joinedGroupListCache = "JOINED_GROUP_LIST_CACHE:" + groupMemberInfoCache = "GROUP_MEMBER_INFO_CACHE:" + groupAllMemberInfoCache = "GROUP_ALL_MEMBER_INFO_CACHE:" + allFriendInfoCache = "ALL_FRIEND_INFO_CACHE:" + allDepartmentCache = "ALL_DEPARTMENT_CACHE:" + allDepartmentMemberCache = "ALL_DEPARTMENT_MEMBER_CACHE:" +) + +func GetFriendIDListFromCache(userID string) ([]string, error) { + getFriendIDList := func() (string, error) { + friendIDList, err := imdb.GetFriendIDListByUserID(userID) + return strings.Join(friendIDList, ","), err + } + friendIDListStr, err := db.DB.Rc.Fetch(friendRelationCache+userID, time.Second, getFriendIDList) + return strings.Split(friendIDListStr, ","), err +} + +func DelFriendIDListFromCache(userID string) error { + err := db.DB.Rc.TagAsDeleted(friendRelationCache + userID) + return err +} + +func GetBlackListFromCache(userID string) ([]string, error) { + getBlackIDList := func() (string, error) { + blackIDList, err := imdb.GetBlackIDListByUserID(userID) + return strings.Join(blackIDList, ","), err + } + blackIDListStr, err := db.DB.Rc.Fetch(blackListCache+userID, time.Second, getBlackIDList) + return strings.Split(blackIDListStr, ","), err +} + +func DelBlackIDListFromCache(userID string) error { + return db.DB.Rc.TagAsDeleted(blackListCache + userID) +} + +func GetJoinedGroupIDListFromCache(userID string) ([]string, error) { + getJoinedGroupIDList := func() (string, error) { + joinedGroupList, err := imdb.GetJoinedGroupIDListByUserID(userID) + return strings.Join(joinedGroupList, ","), err + } + joinedGroupIDListStr, err := db.DB.Rc.Fetch(joinedGroupListCache+userID, time.Second, getJoinedGroupIDList) + return strings.Split(joinedGroupIDListStr, ","), err +} + +func DelJoinedGroupIDListFromCache(userID string) error { + return db.DB.Rc.TagAsDeleted(joinedGroupListCache + userID) +} + +func GetGroupOwnerFromCache(groupID string) (string, error) { + getGroupOwnerIDList := func() (string, error) { + groupOwner, err := imdb.GetGroupOwnerInfoByGroupID(groupID) + if err != nil { + return "", err + } + return groupOwner.UserID, err + } + groupOwnerID, err := db.DB.Rc.Fetch(groupOwnerIDCache+groupID, time.Second, getGroupOwnerIDList) + return groupOwnerID, err +} + +func DelGroupOwnerListFromCache(groupID string) error { + return db.DB.Rc.TagAsDeleted(groupOwnerIDCache + groupID) +} + +func GetGroupMemberIDListFromCache(groupID string) ([]string, error) { + getGroupMemberIDList := func() (string, error) { + groupMemberIDList, err := imdb.GetGroupMemberIDListByGroupID(groupID) + return strings.Join(groupMemberIDList, ","), err + } + groupIDListStr, err := db.DB.Rc.Fetch(groupCache+groupID, time.Second, getGroupMemberIDList) + return strings.Split(groupIDListStr, ","), err +} + +func DelGroupMemberIDListFromCache(userID string) error { + err := db.DB.Rc.TagAsDeleted(groupCache + userID) + return err +} + +func GetUserInfoFromCache(userID string) (*db.User, error) { + getUserInfo := func() (string, error) { + userInfo, err := imdb.GetUserByUserID(userID) + if err != nil { + return "", err + } + bytes, err := json.Marshal(userInfo) + return string(bytes), err + } + userInfoStr, err := db.DB.Rc.Fetch(userInfoCache+userID, time.Second, getUserInfo) + if err != nil { + return nil, err + } + userInfo := &db.User{} + err = json.Unmarshal([]byte(userInfoStr), userInfo) + return userInfo, err +} + +func DelUserInfoFromCache(userID string) error { + return db.DB.Rc.TagAsDeleted(userInfoCache + userID) +} + +func GetGroupMemberInfoFromCache(groupID, userID string) (*db.GroupMember, error) { + getGroupMemberInfo := func() (string, error) { + groupMemberInfo, err := imdb.GetGroupMemberInfoByGroupIDAndUserID(groupID, userID) + if err != nil { + return "", err + } + bytes, err := json.Marshal(groupMemberInfo) + return string(bytes), err + } + groupMemberInfoStr, err := db.DB.Rc.Fetch(groupMemberInfoCache+groupID+"-"+userID, time.Second, getGroupMemberInfo) + if err != nil { + return nil, err + } + groupMember := &db.GroupMember{} + err = json.Unmarshal([]byte(groupMemberInfoStr), groupMember) + return groupMember, err +} + +func DelGroupMemberInfoFromCache(groupID, userID string) error { + return db.DB.Rc.TagAsDeleted(groupMemberInfoCache + groupID + "-" + userID) +} + +func GetAllGroupMembersInfoFromCache(groupID string) ([]*db.GroupMember, error) { + getGroupMemberInfo := func() (string, error) { + groupMembers, err := imdb.GetGroupMemberListByGroupID(groupID) + if err != nil { + return "", err + } + bytes, err := json.Marshal(groupMembers) + return string(bytes), err + } + groupMembersStr, err := db.DB.Rc.Fetch(groupAllMemberInfoCache+groupID, time.Second, getGroupMemberInfo) + if err != nil { + return nil, err + } + var groupMembers []*db.GroupMember + err = json.Unmarshal([]byte(groupMembersStr), &groupMembers) + return groupMembers, err +} + +func DelAllGroupMembersInfoFromCache(groupID string) error { + return db.DB.Rc.TagAsDeleted(groupAllMemberInfoCache + groupID) +} + +func GetGroupInfoFromCache(groupID string) (*db.Group, error) { + getGroupInfo := func() (string, error) { + groupInfo, err := imdb.GetGroupInfoByGroupID(groupID) + if err != nil { + return "", err + } + bytes, err := json.Marshal(groupInfo) + return string(bytes), err + } + groupInfoStr, err := db.DB.Rc.Fetch(groupInfoCache+groupID, time.Second, getGroupInfo) + if err != nil { + return nil, err + } + groupInfo := &db.Group{} + err = json.Unmarshal([]byte(groupInfoStr), groupInfo) + return groupInfo, err +} + +func DelGroupInfoFromCache(groupID string) error { + return db.DB.Rc.TagAsDeleted(groupInfoCache + groupID) +} + +func GetAllFriendsInfoFromCache(userID string) ([]*db.Friend, error) { + getAllFriendInfo := func() (string, error) { + friendInfoList, err := imdb.GetFriendListByUserID(userID) + if err != nil { + return "", err + } + bytes, err := json.Marshal(friendInfoList) + return string(bytes), err + } + allFriendInfoStr, err := db.DB.Rc.Fetch(allFriendInfoCache+userID, time.Second, getAllFriendInfo) + if err != nil { + return nil, err + } + var friendInfoList []*db.Friend + err = json.Unmarshal([]byte(allFriendInfoStr), &friendInfoList) + return friendInfoList, err +} + +func DelAllFriendsInfoFromCache(userID string) error { + return db.DB.Rc.TagAsDeleted(allFriendInfoCache + userID) +} + +func GetAllDepartmentsFromCache() ([]*db.Department, error) { + getAllDepartments := func() (string, error) { + departmentList, err := imdb.GetSubDepartmentList("-1") + if err != nil { + return "", err + } + bytes, err := json.Marshal(departmentList) + return string(bytes), err + } + allDepartmentsStr, err := db.DB.Rc.Fetch(allDepartmentCache, time.Second, getAllDepartments) + if err != nil { + return nil, err + } + var allDepartments []*db.Department + err = json.Unmarshal([]byte(allDepartmentsStr), &allDepartments) + return allDepartments, err +} + +func DelAllDepartmentsFromCache() error { + return db.DB.Rc.TagAsDeleted(allDepartmentCache) +} + +func GetAllDepartmentMembersFromCache() ([]*db.DepartmentMember, error) { + getAllDepartmentMembers := func() (string, error) { + departmentMembers, err := imdb.GetDepartmentMemberList("-1") + if err != nil { + return "", err + } + bytes, err := json.Marshal(departmentMembers) + return string(bytes), err + } + allDepartmentMembersStr, err := db.DB.Rc.Fetch(allDepartmentMemberCache, time.Second, getAllDepartmentMembers) + if err != nil { + return nil, err + } + var allDepartmentMembers []*db.DepartmentMember + err = json.Unmarshal([]byte(allDepartmentMembersStr), &allDepartmentMembers) + return allDepartmentMembers, err +} + +func DelAllDepartmentMembersFromCache() error { + return db.DB.Rc.TagAsDeleted(allDepartmentMemberCache) +} diff --git a/pkg/common/utils/utils.go b/pkg/common/utils/utils.go index cf7019492..1f6df3cd0 100644 --- a/pkg/common/utils/utils.go +++ b/pkg/common/utils/utils.go @@ -93,7 +93,8 @@ func GroupDBCopyOpenIM(dst *open_im_sdk.GroupInfo, src *db.Group) error { } dst.OwnerUserID = user.UserID - dst.MemberCount, err = imdb.GetGroupMemberNumByGroupID(src.GroupID) + memberCount, err := imdb.GetGroupMemberNumByGroupID(src.GroupID) + dst.MemberCount = uint32(memberCount) if err != nil { return utils.Wrap(err, "") } diff --git a/pkg/proto/cache/cache.pb.go b/pkg/proto/cache/cache.pb.go index 157bf4763..48704703f 100644 --- a/pkg/proto/cache/cache.pb.go +++ b/pkg/proto/cache/cache.pb.go @@ -6,7 +6,7 @@ package cache // import "./cache" import proto "github.com/golang/protobuf/proto" import fmt "fmt" import math "math" -import sdk_ws "Open_IM/pkg/proto/sdk_ws" +import _ "Open_IM/pkg/proto/sdk_ws" import ( context "golang.org/x/net/context" @@ -36,7 +36,7 @@ func (m *CommonResp) Reset() { *m = CommonResp{} } func (m *CommonResp) String() string { return proto.CompactTextString(m) } func (*CommonResp) ProtoMessage() {} func (*CommonResp) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_cf8751e0f76be356, []int{0} + return fileDescriptor_cache_dd6bac081ee50bd6, []int{0} } func (m *CommonResp) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_CommonResp.Unmarshal(m, b) @@ -70,182 +70,6 @@ func (m *CommonResp) GetErrMsg() string { return "" } -type GetUserInfoFromCacheReq struct { - UserIDList []string `protobuf:"bytes,1,rep,name=userIDList" json:"userIDList,omitempty"` - OperationID string `protobuf:"bytes,2,opt,name=operationID" json:"operationID,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *GetUserInfoFromCacheReq) Reset() { *m = GetUserInfoFromCacheReq{} } -func (m *GetUserInfoFromCacheReq) String() string { return proto.CompactTextString(m) } -func (*GetUserInfoFromCacheReq) ProtoMessage() {} -func (*GetUserInfoFromCacheReq) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_cf8751e0f76be356, []int{1} -} -func (m *GetUserInfoFromCacheReq) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_GetUserInfoFromCacheReq.Unmarshal(m, b) -} -func (m *GetUserInfoFromCacheReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_GetUserInfoFromCacheReq.Marshal(b, m, deterministic) -} -func (dst *GetUserInfoFromCacheReq) XXX_Merge(src proto.Message) { - xxx_messageInfo_GetUserInfoFromCacheReq.Merge(dst, src) -} -func (m *GetUserInfoFromCacheReq) XXX_Size() int { - return xxx_messageInfo_GetUserInfoFromCacheReq.Size(m) -} -func (m *GetUserInfoFromCacheReq) XXX_DiscardUnknown() { - xxx_messageInfo_GetUserInfoFromCacheReq.DiscardUnknown(m) -} - -var xxx_messageInfo_GetUserInfoFromCacheReq proto.InternalMessageInfo - -func (m *GetUserInfoFromCacheReq) GetUserIDList() []string { - if m != nil { - return m.UserIDList - } - return nil -} - -func (m *GetUserInfoFromCacheReq) GetOperationID() string { - if m != nil { - return m.OperationID - } - return "" -} - -type GetUserInfoFromCacheResp struct { - CommonResp *CommonResp `protobuf:"bytes,1,opt,name=commonResp" json:"commonResp,omitempty"` - UserInfoList []*sdk_ws.UserInfo `protobuf:"bytes,2,rep,name=userInfoList" json:"userInfoList,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *GetUserInfoFromCacheResp) Reset() { *m = GetUserInfoFromCacheResp{} } -func (m *GetUserInfoFromCacheResp) String() string { return proto.CompactTextString(m) } -func (*GetUserInfoFromCacheResp) ProtoMessage() {} -func (*GetUserInfoFromCacheResp) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_cf8751e0f76be356, []int{2} -} -func (m *GetUserInfoFromCacheResp) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_GetUserInfoFromCacheResp.Unmarshal(m, b) -} -func (m *GetUserInfoFromCacheResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_GetUserInfoFromCacheResp.Marshal(b, m, deterministic) -} -func (dst *GetUserInfoFromCacheResp) XXX_Merge(src proto.Message) { - xxx_messageInfo_GetUserInfoFromCacheResp.Merge(dst, src) -} -func (m *GetUserInfoFromCacheResp) XXX_Size() int { - return xxx_messageInfo_GetUserInfoFromCacheResp.Size(m) -} -func (m *GetUserInfoFromCacheResp) XXX_DiscardUnknown() { - xxx_messageInfo_GetUserInfoFromCacheResp.DiscardUnknown(m) -} - -var xxx_messageInfo_GetUserInfoFromCacheResp proto.InternalMessageInfo - -func (m *GetUserInfoFromCacheResp) GetCommonResp() *CommonResp { - if m != nil { - return m.CommonResp - } - return nil -} - -func (m *GetUserInfoFromCacheResp) GetUserInfoList() []*sdk_ws.UserInfo { - if m != nil { - return m.UserInfoList - } - return nil -} - -type UpdateUserInfoToCacheReq struct { - UserInfoList []*sdk_ws.UserInfo `protobuf:"bytes,1,rep,name=userInfoList" json:"userInfoList,omitempty"` - OperationID string `protobuf:"bytes,2,opt,name=operationID" json:"operationID,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *UpdateUserInfoToCacheReq) Reset() { *m = UpdateUserInfoToCacheReq{} } -func (m *UpdateUserInfoToCacheReq) String() string { return proto.CompactTextString(m) } -func (*UpdateUserInfoToCacheReq) ProtoMessage() {} -func (*UpdateUserInfoToCacheReq) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_cf8751e0f76be356, []int{3} -} -func (m *UpdateUserInfoToCacheReq) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_UpdateUserInfoToCacheReq.Unmarshal(m, b) -} -func (m *UpdateUserInfoToCacheReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_UpdateUserInfoToCacheReq.Marshal(b, m, deterministic) -} -func (dst *UpdateUserInfoToCacheReq) XXX_Merge(src proto.Message) { - xxx_messageInfo_UpdateUserInfoToCacheReq.Merge(dst, src) -} -func (m *UpdateUserInfoToCacheReq) XXX_Size() int { - return xxx_messageInfo_UpdateUserInfoToCacheReq.Size(m) -} -func (m *UpdateUserInfoToCacheReq) XXX_DiscardUnknown() { - xxx_messageInfo_UpdateUserInfoToCacheReq.DiscardUnknown(m) -} - -var xxx_messageInfo_UpdateUserInfoToCacheReq proto.InternalMessageInfo - -func (m *UpdateUserInfoToCacheReq) GetUserInfoList() []*sdk_ws.UserInfo { - if m != nil { - return m.UserInfoList - } - return nil -} - -func (m *UpdateUserInfoToCacheReq) GetOperationID() string { - if m != nil { - return m.OperationID - } - return "" -} - -type UpdateUserInfoToCacheResp struct { - CommonResp *CommonResp `protobuf:"bytes,1,opt,name=commonResp" json:"commonResp,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *UpdateUserInfoToCacheResp) Reset() { *m = UpdateUserInfoToCacheResp{} } -func (m *UpdateUserInfoToCacheResp) String() string { return proto.CompactTextString(m) } -func (*UpdateUserInfoToCacheResp) ProtoMessage() {} -func (*UpdateUserInfoToCacheResp) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_cf8751e0f76be356, []int{4} -} -func (m *UpdateUserInfoToCacheResp) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_UpdateUserInfoToCacheResp.Unmarshal(m, b) -} -func (m *UpdateUserInfoToCacheResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_UpdateUserInfoToCacheResp.Marshal(b, m, deterministic) -} -func (dst *UpdateUserInfoToCacheResp) XXX_Merge(src proto.Message) { - xxx_messageInfo_UpdateUserInfoToCacheResp.Merge(dst, src) -} -func (m *UpdateUserInfoToCacheResp) XXX_Size() int { - return xxx_messageInfo_UpdateUserInfoToCacheResp.Size(m) -} -func (m *UpdateUserInfoToCacheResp) XXX_DiscardUnknown() { - xxx_messageInfo_UpdateUserInfoToCacheResp.DiscardUnknown(m) -} - -var xxx_messageInfo_UpdateUserInfoToCacheResp proto.InternalMessageInfo - -func (m *UpdateUserInfoToCacheResp) GetCommonResp() *CommonResp { - if m != nil { - return m.CommonResp - } - return nil -} - type GetFriendIDListFromCacheReq struct { UserID string `protobuf:"bytes,1,opt,name=userID" json:"userID,omitempty"` OperationID string `protobuf:"bytes,2,opt,name=operationID" json:"operationID,omitempty"` @@ -258,7 +82,7 @@ func (m *GetFriendIDListFromCacheReq) Reset() { *m = GetFriendIDListFrom func (m *GetFriendIDListFromCacheReq) String() string { return proto.CompactTextString(m) } func (*GetFriendIDListFromCacheReq) ProtoMessage() {} func (*GetFriendIDListFromCacheReq) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_cf8751e0f76be356, []int{5} + return fileDescriptor_cache_dd6bac081ee50bd6, []int{1} } func (m *GetFriendIDListFromCacheReq) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_GetFriendIDListFromCacheReq.Unmarshal(m, b) @@ -304,7 +128,7 @@ func (m *GetFriendIDListFromCacheResp) Reset() { *m = GetFriendIDListFro func (m *GetFriendIDListFromCacheResp) String() string { return proto.CompactTextString(m) } func (*GetFriendIDListFromCacheResp) ProtoMessage() {} func (*GetFriendIDListFromCacheResp) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_cf8751e0f76be356, []int{6} + return fileDescriptor_cache_dd6bac081ee50bd6, []int{2} } func (m *GetFriendIDListFromCacheResp) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_GetFriendIDListFromCacheResp.Unmarshal(m, b) @@ -338,184 +162,84 @@ func (m *GetFriendIDListFromCacheResp) GetCommonResp() *CommonResp { return nil } -type AddFriendToCacheReq struct { - UserID string `protobuf:"bytes,1,opt,name=userID" json:"userID,omitempty"` - FriendID string `protobuf:"bytes,2,opt,name=friendID" json:"friendID,omitempty"` - OperationID string `protobuf:"bytes,3,opt,name=operationID" json:"operationID,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *AddFriendToCacheReq) Reset() { *m = AddFriendToCacheReq{} } -func (m *AddFriendToCacheReq) String() string { return proto.CompactTextString(m) } -func (*AddFriendToCacheReq) ProtoMessage() {} -func (*AddFriendToCacheReq) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_cf8751e0f76be356, []int{7} -} -func (m *AddFriendToCacheReq) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_AddFriendToCacheReq.Unmarshal(m, b) -} -func (m *AddFriendToCacheReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_AddFriendToCacheReq.Marshal(b, m, deterministic) -} -func (dst *AddFriendToCacheReq) XXX_Merge(src proto.Message) { - xxx_messageInfo_AddFriendToCacheReq.Merge(dst, src) -} -func (m *AddFriendToCacheReq) XXX_Size() int { - return xxx_messageInfo_AddFriendToCacheReq.Size(m) -} -func (m *AddFriendToCacheReq) XXX_DiscardUnknown() { - xxx_messageInfo_AddFriendToCacheReq.DiscardUnknown(m) -} - -var xxx_messageInfo_AddFriendToCacheReq proto.InternalMessageInfo - -func (m *AddFriendToCacheReq) GetUserID() string { - if m != nil { - return m.UserID - } - return "" -} - -func (m *AddFriendToCacheReq) GetFriendID() string { - if m != nil { - return m.FriendID - } - return "" -} - -func (m *AddFriendToCacheReq) GetOperationID() string { - if m != nil { - return m.OperationID - } - return "" -} - -type AddFriendToCacheResp struct { - CommonResp *CommonResp `protobuf:"bytes,1,opt,name=commonResp" json:"commonResp,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *AddFriendToCacheResp) Reset() { *m = AddFriendToCacheResp{} } -func (m *AddFriendToCacheResp) String() string { return proto.CompactTextString(m) } -func (*AddFriendToCacheResp) ProtoMessage() {} -func (*AddFriendToCacheResp) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_cf8751e0f76be356, []int{8} -} -func (m *AddFriendToCacheResp) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_AddFriendToCacheResp.Unmarshal(m, b) -} -func (m *AddFriendToCacheResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_AddFriendToCacheResp.Marshal(b, m, deterministic) -} -func (dst *AddFriendToCacheResp) XXX_Merge(src proto.Message) { - xxx_messageInfo_AddFriendToCacheResp.Merge(dst, src) -} -func (m *AddFriendToCacheResp) XXX_Size() int { - return xxx_messageInfo_AddFriendToCacheResp.Size(m) -} -func (m *AddFriendToCacheResp) XXX_DiscardUnknown() { - xxx_messageInfo_AddFriendToCacheResp.DiscardUnknown(m) -} - -var xxx_messageInfo_AddFriendToCacheResp proto.InternalMessageInfo - -func (m *AddFriendToCacheResp) GetCommonResp() *CommonResp { - if m != nil { - return m.CommonResp - } - return nil -} - -type ReduceFriendFromCacheReq struct { +type DelFriendIDListFromCacheReq struct { UserID string `protobuf:"bytes,1,opt,name=userID" json:"userID,omitempty"` - FriendID string `protobuf:"bytes,2,opt,name=friendID" json:"friendID,omitempty"` - OperationID string `protobuf:"bytes,3,opt,name=operationID" json:"operationID,omitempty"` + OperationID string `protobuf:"bytes,2,opt,name=operationID" json:"operationID,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` } -func (m *ReduceFriendFromCacheReq) Reset() { *m = ReduceFriendFromCacheReq{} } -func (m *ReduceFriendFromCacheReq) String() string { return proto.CompactTextString(m) } -func (*ReduceFriendFromCacheReq) ProtoMessage() {} -func (*ReduceFriendFromCacheReq) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_cf8751e0f76be356, []int{9} +func (m *DelFriendIDListFromCacheReq) Reset() { *m = DelFriendIDListFromCacheReq{} } +func (m *DelFriendIDListFromCacheReq) String() string { return proto.CompactTextString(m) } +func (*DelFriendIDListFromCacheReq) ProtoMessage() {} +func (*DelFriendIDListFromCacheReq) Descriptor() ([]byte, []int) { + return fileDescriptor_cache_dd6bac081ee50bd6, []int{3} } -func (m *ReduceFriendFromCacheReq) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ReduceFriendFromCacheReq.Unmarshal(m, b) +func (m *DelFriendIDListFromCacheReq) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DelFriendIDListFromCacheReq.Unmarshal(m, b) } -func (m *ReduceFriendFromCacheReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ReduceFriendFromCacheReq.Marshal(b, m, deterministic) +func (m *DelFriendIDListFromCacheReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DelFriendIDListFromCacheReq.Marshal(b, m, deterministic) } -func (dst *ReduceFriendFromCacheReq) XXX_Merge(src proto.Message) { - xxx_messageInfo_ReduceFriendFromCacheReq.Merge(dst, src) +func (dst *DelFriendIDListFromCacheReq) XXX_Merge(src proto.Message) { + xxx_messageInfo_DelFriendIDListFromCacheReq.Merge(dst, src) } -func (m *ReduceFriendFromCacheReq) XXX_Size() int { - return xxx_messageInfo_ReduceFriendFromCacheReq.Size(m) +func (m *DelFriendIDListFromCacheReq) XXX_Size() int { + return xxx_messageInfo_DelFriendIDListFromCacheReq.Size(m) } -func (m *ReduceFriendFromCacheReq) XXX_DiscardUnknown() { - xxx_messageInfo_ReduceFriendFromCacheReq.DiscardUnknown(m) +func (m *DelFriendIDListFromCacheReq) XXX_DiscardUnknown() { + xxx_messageInfo_DelFriendIDListFromCacheReq.DiscardUnknown(m) } -var xxx_messageInfo_ReduceFriendFromCacheReq proto.InternalMessageInfo +var xxx_messageInfo_DelFriendIDListFromCacheReq proto.InternalMessageInfo -func (m *ReduceFriendFromCacheReq) GetUserID() string { +func (m *DelFriendIDListFromCacheReq) GetUserID() string { if m != nil { return m.UserID } return "" } -func (m *ReduceFriendFromCacheReq) GetFriendID() string { - if m != nil { - return m.FriendID - } - return "" -} - -func (m *ReduceFriendFromCacheReq) GetOperationID() string { +func (m *DelFriendIDListFromCacheReq) GetOperationID() string { if m != nil { return m.OperationID } return "" } -type ReduceFriendFromCacheResp struct { +type DelFriendIDListFromCacheResp struct { CommonResp *CommonResp `protobuf:"bytes,1,opt,name=commonResp" json:"commonResp,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` } -func (m *ReduceFriendFromCacheResp) Reset() { *m = ReduceFriendFromCacheResp{} } -func (m *ReduceFriendFromCacheResp) String() string { return proto.CompactTextString(m) } -func (*ReduceFriendFromCacheResp) ProtoMessage() {} -func (*ReduceFriendFromCacheResp) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_cf8751e0f76be356, []int{10} +func (m *DelFriendIDListFromCacheResp) Reset() { *m = DelFriendIDListFromCacheResp{} } +func (m *DelFriendIDListFromCacheResp) String() string { return proto.CompactTextString(m) } +func (*DelFriendIDListFromCacheResp) ProtoMessage() {} +func (*DelFriendIDListFromCacheResp) Descriptor() ([]byte, []int) { + return fileDescriptor_cache_dd6bac081ee50bd6, []int{4} } -func (m *ReduceFriendFromCacheResp) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ReduceFriendFromCacheResp.Unmarshal(m, b) +func (m *DelFriendIDListFromCacheResp) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DelFriendIDListFromCacheResp.Unmarshal(m, b) } -func (m *ReduceFriendFromCacheResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ReduceFriendFromCacheResp.Marshal(b, m, deterministic) +func (m *DelFriendIDListFromCacheResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DelFriendIDListFromCacheResp.Marshal(b, m, deterministic) } -func (dst *ReduceFriendFromCacheResp) XXX_Merge(src proto.Message) { - xxx_messageInfo_ReduceFriendFromCacheResp.Merge(dst, src) +func (dst *DelFriendIDListFromCacheResp) XXX_Merge(src proto.Message) { + xxx_messageInfo_DelFriendIDListFromCacheResp.Merge(dst, src) } -func (m *ReduceFriendFromCacheResp) XXX_Size() int { - return xxx_messageInfo_ReduceFriendFromCacheResp.Size(m) +func (m *DelFriendIDListFromCacheResp) XXX_Size() int { + return xxx_messageInfo_DelFriendIDListFromCacheResp.Size(m) } -func (m *ReduceFriendFromCacheResp) XXX_DiscardUnknown() { - xxx_messageInfo_ReduceFriendFromCacheResp.DiscardUnknown(m) +func (m *DelFriendIDListFromCacheResp) XXX_DiscardUnknown() { + xxx_messageInfo_DelFriendIDListFromCacheResp.DiscardUnknown(m) } -var xxx_messageInfo_ReduceFriendFromCacheResp proto.InternalMessageInfo +var xxx_messageInfo_DelFriendIDListFromCacheResp proto.InternalMessageInfo -func (m *ReduceFriendFromCacheResp) GetCommonResp() *CommonResp { +func (m *DelFriendIDListFromCacheResp) GetCommonResp() *CommonResp { if m != nil { return m.CommonResp } @@ -534,7 +258,7 @@ func (m *GetBlackIDListFromCacheReq) Reset() { *m = GetBlackIDListFromCa func (m *GetBlackIDListFromCacheReq) String() string { return proto.CompactTextString(m) } func (*GetBlackIDListFromCacheReq) ProtoMessage() {} func (*GetBlackIDListFromCacheReq) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_cf8751e0f76be356, []int{11} + return fileDescriptor_cache_dd6bac081ee50bd6, []int{5} } func (m *GetBlackIDListFromCacheReq) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_GetBlackIDListFromCacheReq.Unmarshal(m, b) @@ -580,7 +304,7 @@ func (m *GetBlackIDListFromCacheResp) Reset() { *m = GetBlackIDListFromC func (m *GetBlackIDListFromCacheResp) String() string { return proto.CompactTextString(m) } func (*GetBlackIDListFromCacheResp) ProtoMessage() {} func (*GetBlackIDListFromCacheResp) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_cf8751e0f76be356, []int{12} + return fileDescriptor_cache_dd6bac081ee50bd6, []int{6} } func (m *GetBlackIDListFromCacheResp) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_GetBlackIDListFromCacheResp.Unmarshal(m, b) @@ -614,184 +338,84 @@ func (m *GetBlackIDListFromCacheResp) GetCommonResp() *CommonResp { return nil } -type AddBlackUserToCacheReq struct { +type DelBlackIDListFromCacheReq struct { UserID string `protobuf:"bytes,1,opt,name=userID" json:"userID,omitempty"` - BlackUserID string `protobuf:"bytes,2,opt,name=blackUserID" json:"blackUserID,omitempty"` - OperationID string `protobuf:"bytes,3,opt,name=operationID" json:"operationID,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *AddBlackUserToCacheReq) Reset() { *m = AddBlackUserToCacheReq{} } -func (m *AddBlackUserToCacheReq) String() string { return proto.CompactTextString(m) } -func (*AddBlackUserToCacheReq) ProtoMessage() {} -func (*AddBlackUserToCacheReq) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_cf8751e0f76be356, []int{13} -} -func (m *AddBlackUserToCacheReq) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_AddBlackUserToCacheReq.Unmarshal(m, b) -} -func (m *AddBlackUserToCacheReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_AddBlackUserToCacheReq.Marshal(b, m, deterministic) -} -func (dst *AddBlackUserToCacheReq) XXX_Merge(src proto.Message) { - xxx_messageInfo_AddBlackUserToCacheReq.Merge(dst, src) -} -func (m *AddBlackUserToCacheReq) XXX_Size() int { - return xxx_messageInfo_AddBlackUserToCacheReq.Size(m) -} -func (m *AddBlackUserToCacheReq) XXX_DiscardUnknown() { - xxx_messageInfo_AddBlackUserToCacheReq.DiscardUnknown(m) -} - -var xxx_messageInfo_AddBlackUserToCacheReq proto.InternalMessageInfo - -func (m *AddBlackUserToCacheReq) GetUserID() string { - if m != nil { - return m.UserID - } - return "" -} - -func (m *AddBlackUserToCacheReq) GetBlackUserID() string { - if m != nil { - return m.BlackUserID - } - return "" -} - -func (m *AddBlackUserToCacheReq) GetOperationID() string { - if m != nil { - return m.OperationID - } - return "" -} - -type AddBlackUserToCacheResp struct { - CommonResp *CommonResp `protobuf:"bytes,1,opt,name=commonResp" json:"commonResp,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *AddBlackUserToCacheResp) Reset() { *m = AddBlackUserToCacheResp{} } -func (m *AddBlackUserToCacheResp) String() string { return proto.CompactTextString(m) } -func (*AddBlackUserToCacheResp) ProtoMessage() {} -func (*AddBlackUserToCacheResp) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_cf8751e0f76be356, []int{14} -} -func (m *AddBlackUserToCacheResp) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_AddBlackUserToCacheResp.Unmarshal(m, b) -} -func (m *AddBlackUserToCacheResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_AddBlackUserToCacheResp.Marshal(b, m, deterministic) -} -func (dst *AddBlackUserToCacheResp) XXX_Merge(src proto.Message) { - xxx_messageInfo_AddBlackUserToCacheResp.Merge(dst, src) -} -func (m *AddBlackUserToCacheResp) XXX_Size() int { - return xxx_messageInfo_AddBlackUserToCacheResp.Size(m) -} -func (m *AddBlackUserToCacheResp) XXX_DiscardUnknown() { - xxx_messageInfo_AddBlackUserToCacheResp.DiscardUnknown(m) -} - -var xxx_messageInfo_AddBlackUserToCacheResp proto.InternalMessageInfo - -func (m *AddBlackUserToCacheResp) GetCommonResp() *CommonResp { - if m != nil { - return m.CommonResp - } - return nil -} - -type ReduceBlackUserFromCacheReq struct { - UserID string `protobuf:"bytes,1,opt,name=userID" json:"userID,omitempty"` - BlackUserID string `protobuf:"bytes,2,opt,name=blackUserID" json:"blackUserID,omitempty"` - OperationID string `protobuf:"bytes,3,opt,name=operationID" json:"operationID,omitempty"` + OperationID string `protobuf:"bytes,2,opt,name=operationID" json:"operationID,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` } -func (m *ReduceBlackUserFromCacheReq) Reset() { *m = ReduceBlackUserFromCacheReq{} } -func (m *ReduceBlackUserFromCacheReq) String() string { return proto.CompactTextString(m) } -func (*ReduceBlackUserFromCacheReq) ProtoMessage() {} -func (*ReduceBlackUserFromCacheReq) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_cf8751e0f76be356, []int{15} +func (m *DelBlackIDListFromCacheReq) Reset() { *m = DelBlackIDListFromCacheReq{} } +func (m *DelBlackIDListFromCacheReq) String() string { return proto.CompactTextString(m) } +func (*DelBlackIDListFromCacheReq) ProtoMessage() {} +func (*DelBlackIDListFromCacheReq) Descriptor() ([]byte, []int) { + return fileDescriptor_cache_dd6bac081ee50bd6, []int{7} } -func (m *ReduceBlackUserFromCacheReq) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ReduceBlackUserFromCacheReq.Unmarshal(m, b) +func (m *DelBlackIDListFromCacheReq) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DelBlackIDListFromCacheReq.Unmarshal(m, b) } -func (m *ReduceBlackUserFromCacheReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ReduceBlackUserFromCacheReq.Marshal(b, m, deterministic) +func (m *DelBlackIDListFromCacheReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DelBlackIDListFromCacheReq.Marshal(b, m, deterministic) } -func (dst *ReduceBlackUserFromCacheReq) XXX_Merge(src proto.Message) { - xxx_messageInfo_ReduceBlackUserFromCacheReq.Merge(dst, src) +func (dst *DelBlackIDListFromCacheReq) XXX_Merge(src proto.Message) { + xxx_messageInfo_DelBlackIDListFromCacheReq.Merge(dst, src) } -func (m *ReduceBlackUserFromCacheReq) XXX_Size() int { - return xxx_messageInfo_ReduceBlackUserFromCacheReq.Size(m) +func (m *DelBlackIDListFromCacheReq) XXX_Size() int { + return xxx_messageInfo_DelBlackIDListFromCacheReq.Size(m) } -func (m *ReduceBlackUserFromCacheReq) XXX_DiscardUnknown() { - xxx_messageInfo_ReduceBlackUserFromCacheReq.DiscardUnknown(m) +func (m *DelBlackIDListFromCacheReq) XXX_DiscardUnknown() { + xxx_messageInfo_DelBlackIDListFromCacheReq.DiscardUnknown(m) } -var xxx_messageInfo_ReduceBlackUserFromCacheReq proto.InternalMessageInfo +var xxx_messageInfo_DelBlackIDListFromCacheReq proto.InternalMessageInfo -func (m *ReduceBlackUserFromCacheReq) GetUserID() string { +func (m *DelBlackIDListFromCacheReq) GetUserID() string { if m != nil { return m.UserID } return "" } -func (m *ReduceBlackUserFromCacheReq) GetBlackUserID() string { - if m != nil { - return m.BlackUserID - } - return "" -} - -func (m *ReduceBlackUserFromCacheReq) GetOperationID() string { +func (m *DelBlackIDListFromCacheReq) GetOperationID() string { if m != nil { return m.OperationID } return "" } -type ReduceBlackUserFromCacheResp struct { +type DelBlackIDListFromCacheResp struct { CommonResp *CommonResp `protobuf:"bytes,1,opt,name=commonResp" json:"commonResp,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` } -func (m *ReduceBlackUserFromCacheResp) Reset() { *m = ReduceBlackUserFromCacheResp{} } -func (m *ReduceBlackUserFromCacheResp) String() string { return proto.CompactTextString(m) } -func (*ReduceBlackUserFromCacheResp) ProtoMessage() {} -func (*ReduceBlackUserFromCacheResp) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_cf8751e0f76be356, []int{16} +func (m *DelBlackIDListFromCacheResp) Reset() { *m = DelBlackIDListFromCacheResp{} } +func (m *DelBlackIDListFromCacheResp) String() string { return proto.CompactTextString(m) } +func (*DelBlackIDListFromCacheResp) ProtoMessage() {} +func (*DelBlackIDListFromCacheResp) Descriptor() ([]byte, []int) { + return fileDescriptor_cache_dd6bac081ee50bd6, []int{8} } -func (m *ReduceBlackUserFromCacheResp) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ReduceBlackUserFromCacheResp.Unmarshal(m, b) +func (m *DelBlackIDListFromCacheResp) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DelBlackIDListFromCacheResp.Unmarshal(m, b) } -func (m *ReduceBlackUserFromCacheResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ReduceBlackUserFromCacheResp.Marshal(b, m, deterministic) +func (m *DelBlackIDListFromCacheResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DelBlackIDListFromCacheResp.Marshal(b, m, deterministic) } -func (dst *ReduceBlackUserFromCacheResp) XXX_Merge(src proto.Message) { - xxx_messageInfo_ReduceBlackUserFromCacheResp.Merge(dst, src) +func (dst *DelBlackIDListFromCacheResp) XXX_Merge(src proto.Message) { + xxx_messageInfo_DelBlackIDListFromCacheResp.Merge(dst, src) } -func (m *ReduceBlackUserFromCacheResp) XXX_Size() int { - return xxx_messageInfo_ReduceBlackUserFromCacheResp.Size(m) +func (m *DelBlackIDListFromCacheResp) XXX_Size() int { + return xxx_messageInfo_DelBlackIDListFromCacheResp.Size(m) } -func (m *ReduceBlackUserFromCacheResp) XXX_DiscardUnknown() { - xxx_messageInfo_ReduceBlackUserFromCacheResp.DiscardUnknown(m) +func (m *DelBlackIDListFromCacheResp) XXX_DiscardUnknown() { + xxx_messageInfo_DelBlackIDListFromCacheResp.DiscardUnknown(m) } -var xxx_messageInfo_ReduceBlackUserFromCacheResp proto.InternalMessageInfo +var xxx_messageInfo_DelBlackIDListFromCacheResp proto.InternalMessageInfo -func (m *ReduceBlackUserFromCacheResp) GetCommonResp() *CommonResp { +func (m *DelBlackIDListFromCacheResp) GetCommonResp() *CommonResp { if m != nil { return m.CommonResp } @@ -810,7 +434,7 @@ func (m *GetGroupMemberIDListFromCacheReq) Reset() { *m = GetGroupMember func (m *GetGroupMemberIDListFromCacheReq) String() string { return proto.CompactTextString(m) } func (*GetGroupMemberIDListFromCacheReq) ProtoMessage() {} func (*GetGroupMemberIDListFromCacheReq) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_cf8751e0f76be356, []int{17} + return fileDescriptor_cache_dd6bac081ee50bd6, []int{9} } func (m *GetGroupMemberIDListFromCacheReq) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_GetGroupMemberIDListFromCacheReq.Unmarshal(m, b) @@ -856,7 +480,7 @@ func (m *GetGroupMemberIDListFromCacheResp) Reset() { *m = GetGroupMembe func (m *GetGroupMemberIDListFromCacheResp) String() string { return proto.CompactTextString(m) } func (*GetGroupMemberIDListFromCacheResp) ProtoMessage() {} func (*GetGroupMemberIDListFromCacheResp) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_cf8751e0f76be356, []int{18} + return fileDescriptor_cache_dd6bac081ee50bd6, []int{10} } func (m *GetGroupMemberIDListFromCacheResp) XXX_Unmarshal(b []byte) error { return xxx_messageInfo_GetGroupMemberIDListFromCacheResp.Unmarshal(m, b) @@ -890,184 +514,84 @@ func (m *GetGroupMemberIDListFromCacheResp) GetUserIDList() []string { return nil } -type AddGroupMemberToCacheReq struct { - UserIDList []string `protobuf:"bytes,1,rep,name=userIDList" json:"userIDList,omitempty"` - GroupID string `protobuf:"bytes,2,opt,name=groupID" json:"groupID,omitempty"` - OperationID string `protobuf:"bytes,3,opt,name=operationID" json:"operationID,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *AddGroupMemberToCacheReq) Reset() { *m = AddGroupMemberToCacheReq{} } -func (m *AddGroupMemberToCacheReq) String() string { return proto.CompactTextString(m) } -func (*AddGroupMemberToCacheReq) ProtoMessage() {} -func (*AddGroupMemberToCacheReq) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_cf8751e0f76be356, []int{19} -} -func (m *AddGroupMemberToCacheReq) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_AddGroupMemberToCacheReq.Unmarshal(m, b) -} -func (m *AddGroupMemberToCacheReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_AddGroupMemberToCacheReq.Marshal(b, m, deterministic) -} -func (dst *AddGroupMemberToCacheReq) XXX_Merge(src proto.Message) { - xxx_messageInfo_AddGroupMemberToCacheReq.Merge(dst, src) -} -func (m *AddGroupMemberToCacheReq) XXX_Size() int { - return xxx_messageInfo_AddGroupMemberToCacheReq.Size(m) -} -func (m *AddGroupMemberToCacheReq) XXX_DiscardUnknown() { - xxx_messageInfo_AddGroupMemberToCacheReq.DiscardUnknown(m) -} - -var xxx_messageInfo_AddGroupMemberToCacheReq proto.InternalMessageInfo - -func (m *AddGroupMemberToCacheReq) GetUserIDList() []string { - if m != nil { - return m.UserIDList - } - return nil -} - -func (m *AddGroupMemberToCacheReq) GetGroupID() string { - if m != nil { - return m.GroupID - } - return "" -} - -func (m *AddGroupMemberToCacheReq) GetOperationID() string { - if m != nil { - return m.OperationID - } - return "" -} - -type AddGroupMemberToCacheResp struct { - CommonResp *CommonResp `protobuf:"bytes,1,opt,name=commonResp" json:"commonResp,omitempty"` - XXX_NoUnkeyedLiteral struct{} `json:"-"` - XXX_unrecognized []byte `json:"-"` - XXX_sizecache int32 `json:"-"` -} - -func (m *AddGroupMemberToCacheResp) Reset() { *m = AddGroupMemberToCacheResp{} } -func (m *AddGroupMemberToCacheResp) String() string { return proto.CompactTextString(m) } -func (*AddGroupMemberToCacheResp) ProtoMessage() {} -func (*AddGroupMemberToCacheResp) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_cf8751e0f76be356, []int{20} -} -func (m *AddGroupMemberToCacheResp) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_AddGroupMemberToCacheResp.Unmarshal(m, b) -} -func (m *AddGroupMemberToCacheResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_AddGroupMemberToCacheResp.Marshal(b, m, deterministic) -} -func (dst *AddGroupMemberToCacheResp) XXX_Merge(src proto.Message) { - xxx_messageInfo_AddGroupMemberToCacheResp.Merge(dst, src) -} -func (m *AddGroupMemberToCacheResp) XXX_Size() int { - return xxx_messageInfo_AddGroupMemberToCacheResp.Size(m) -} -func (m *AddGroupMemberToCacheResp) XXX_DiscardUnknown() { - xxx_messageInfo_AddGroupMemberToCacheResp.DiscardUnknown(m) -} - -var xxx_messageInfo_AddGroupMemberToCacheResp proto.InternalMessageInfo - -func (m *AddGroupMemberToCacheResp) GetCommonResp() *CommonResp { - if m != nil { - return m.CommonResp - } - return nil -} - -type ReduceGroupMemberFromCacheReq struct { - UserIDList []string `protobuf:"bytes,1,rep,name=userIDList" json:"userIDList,omitempty"` - GroupID string `protobuf:"bytes,2,opt,name=groupID" json:"groupID,omitempty"` - OperationID string `protobuf:"bytes,3,opt,name=operationID" json:"operationID,omitempty"` +type DelGroupMemberIDListFromCacheReq struct { + GroupID string `protobuf:"bytes,1,opt,name=groupID" json:"groupID,omitempty"` + OperationID string `protobuf:"bytes,2,opt,name=operationID" json:"operationID,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` } -func (m *ReduceGroupMemberFromCacheReq) Reset() { *m = ReduceGroupMemberFromCacheReq{} } -func (m *ReduceGroupMemberFromCacheReq) String() string { return proto.CompactTextString(m) } -func (*ReduceGroupMemberFromCacheReq) ProtoMessage() {} -func (*ReduceGroupMemberFromCacheReq) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_cf8751e0f76be356, []int{21} +func (m *DelGroupMemberIDListFromCacheReq) Reset() { *m = DelGroupMemberIDListFromCacheReq{} } +func (m *DelGroupMemberIDListFromCacheReq) String() string { return proto.CompactTextString(m) } +func (*DelGroupMemberIDListFromCacheReq) ProtoMessage() {} +func (*DelGroupMemberIDListFromCacheReq) Descriptor() ([]byte, []int) { + return fileDescriptor_cache_dd6bac081ee50bd6, []int{11} } -func (m *ReduceGroupMemberFromCacheReq) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ReduceGroupMemberFromCacheReq.Unmarshal(m, b) +func (m *DelGroupMemberIDListFromCacheReq) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DelGroupMemberIDListFromCacheReq.Unmarshal(m, b) } -func (m *ReduceGroupMemberFromCacheReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ReduceGroupMemberFromCacheReq.Marshal(b, m, deterministic) +func (m *DelGroupMemberIDListFromCacheReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DelGroupMemberIDListFromCacheReq.Marshal(b, m, deterministic) } -func (dst *ReduceGroupMemberFromCacheReq) XXX_Merge(src proto.Message) { - xxx_messageInfo_ReduceGroupMemberFromCacheReq.Merge(dst, src) +func (dst *DelGroupMemberIDListFromCacheReq) XXX_Merge(src proto.Message) { + xxx_messageInfo_DelGroupMemberIDListFromCacheReq.Merge(dst, src) } -func (m *ReduceGroupMemberFromCacheReq) XXX_Size() int { - return xxx_messageInfo_ReduceGroupMemberFromCacheReq.Size(m) +func (m *DelGroupMemberIDListFromCacheReq) XXX_Size() int { + return xxx_messageInfo_DelGroupMemberIDListFromCacheReq.Size(m) } -func (m *ReduceGroupMemberFromCacheReq) XXX_DiscardUnknown() { - xxx_messageInfo_ReduceGroupMemberFromCacheReq.DiscardUnknown(m) +func (m *DelGroupMemberIDListFromCacheReq) XXX_DiscardUnknown() { + xxx_messageInfo_DelGroupMemberIDListFromCacheReq.DiscardUnknown(m) } -var xxx_messageInfo_ReduceGroupMemberFromCacheReq proto.InternalMessageInfo - -func (m *ReduceGroupMemberFromCacheReq) GetUserIDList() []string { - if m != nil { - return m.UserIDList - } - return nil -} +var xxx_messageInfo_DelGroupMemberIDListFromCacheReq proto.InternalMessageInfo -func (m *ReduceGroupMemberFromCacheReq) GetGroupID() string { +func (m *DelGroupMemberIDListFromCacheReq) GetGroupID() string { if m != nil { return m.GroupID } return "" } -func (m *ReduceGroupMemberFromCacheReq) GetOperationID() string { +func (m *DelGroupMemberIDListFromCacheReq) GetOperationID() string { if m != nil { return m.OperationID } return "" } -type ReduceGroupMemberFromCacheResp struct { +type DelGroupMemberIDListFromCacheResp struct { CommonResp *CommonResp `protobuf:"bytes,1,opt,name=commonResp" json:"commonResp,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` } -func (m *ReduceGroupMemberFromCacheResp) Reset() { *m = ReduceGroupMemberFromCacheResp{} } -func (m *ReduceGroupMemberFromCacheResp) String() string { return proto.CompactTextString(m) } -func (*ReduceGroupMemberFromCacheResp) ProtoMessage() {} -func (*ReduceGroupMemberFromCacheResp) Descriptor() ([]byte, []int) { - return fileDescriptor_cache_cf8751e0f76be356, []int{22} +func (m *DelGroupMemberIDListFromCacheResp) Reset() { *m = DelGroupMemberIDListFromCacheResp{} } +func (m *DelGroupMemberIDListFromCacheResp) String() string { return proto.CompactTextString(m) } +func (*DelGroupMemberIDListFromCacheResp) ProtoMessage() {} +func (*DelGroupMemberIDListFromCacheResp) Descriptor() ([]byte, []int) { + return fileDescriptor_cache_dd6bac081ee50bd6, []int{12} } -func (m *ReduceGroupMemberFromCacheResp) XXX_Unmarshal(b []byte) error { - return xxx_messageInfo_ReduceGroupMemberFromCacheResp.Unmarshal(m, b) +func (m *DelGroupMemberIDListFromCacheResp) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_DelGroupMemberIDListFromCacheResp.Unmarshal(m, b) } -func (m *ReduceGroupMemberFromCacheResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - return xxx_messageInfo_ReduceGroupMemberFromCacheResp.Marshal(b, m, deterministic) +func (m *DelGroupMemberIDListFromCacheResp) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_DelGroupMemberIDListFromCacheResp.Marshal(b, m, deterministic) } -func (dst *ReduceGroupMemberFromCacheResp) XXX_Merge(src proto.Message) { - xxx_messageInfo_ReduceGroupMemberFromCacheResp.Merge(dst, src) +func (dst *DelGroupMemberIDListFromCacheResp) XXX_Merge(src proto.Message) { + xxx_messageInfo_DelGroupMemberIDListFromCacheResp.Merge(dst, src) } -func (m *ReduceGroupMemberFromCacheResp) XXX_Size() int { - return xxx_messageInfo_ReduceGroupMemberFromCacheResp.Size(m) +func (m *DelGroupMemberIDListFromCacheResp) XXX_Size() int { + return xxx_messageInfo_DelGroupMemberIDListFromCacheResp.Size(m) } -func (m *ReduceGroupMemberFromCacheResp) XXX_DiscardUnknown() { - xxx_messageInfo_ReduceGroupMemberFromCacheResp.DiscardUnknown(m) +func (m *DelGroupMemberIDListFromCacheResp) XXX_DiscardUnknown() { + xxx_messageInfo_DelGroupMemberIDListFromCacheResp.DiscardUnknown(m) } -var xxx_messageInfo_ReduceGroupMemberFromCacheResp proto.InternalMessageInfo +var xxx_messageInfo_DelGroupMemberIDListFromCacheResp proto.InternalMessageInfo -func (m *ReduceGroupMemberFromCacheResp) GetCommonResp() *CommonResp { +func (m *DelGroupMemberIDListFromCacheResp) GetCommonResp() *CommonResp { if m != nil { return m.CommonResp } @@ -1076,28 +600,18 @@ func (m *ReduceGroupMemberFromCacheResp) GetCommonResp() *CommonResp { func init() { proto.RegisterType((*CommonResp)(nil), "cache.CommonResp") - proto.RegisterType((*GetUserInfoFromCacheReq)(nil), "cache.GetUserInfoFromCacheReq") - proto.RegisterType((*GetUserInfoFromCacheResp)(nil), "cache.GetUserInfoFromCacheResp") - proto.RegisterType((*UpdateUserInfoToCacheReq)(nil), "cache.UpdateUserInfoToCacheReq") - proto.RegisterType((*UpdateUserInfoToCacheResp)(nil), "cache.UpdateUserInfoToCacheResp") proto.RegisterType((*GetFriendIDListFromCacheReq)(nil), "cache.GetFriendIDListFromCacheReq") proto.RegisterType((*GetFriendIDListFromCacheResp)(nil), "cache.GetFriendIDListFromCacheResp") - proto.RegisterType((*AddFriendToCacheReq)(nil), "cache.AddFriendToCacheReq") - proto.RegisterType((*AddFriendToCacheResp)(nil), "cache.AddFriendToCacheResp") - proto.RegisterType((*ReduceFriendFromCacheReq)(nil), "cache.ReduceFriendFromCacheReq") - proto.RegisterType((*ReduceFriendFromCacheResp)(nil), "cache.ReduceFriendFromCacheResp") + proto.RegisterType((*DelFriendIDListFromCacheReq)(nil), "cache.DelFriendIDListFromCacheReq") + proto.RegisterType((*DelFriendIDListFromCacheResp)(nil), "cache.DelFriendIDListFromCacheResp") proto.RegisterType((*GetBlackIDListFromCacheReq)(nil), "cache.GetBlackIDListFromCacheReq") proto.RegisterType((*GetBlackIDListFromCacheResp)(nil), "cache.GetBlackIDListFromCacheResp") - proto.RegisterType((*AddBlackUserToCacheReq)(nil), "cache.AddBlackUserToCacheReq") - proto.RegisterType((*AddBlackUserToCacheResp)(nil), "cache.AddBlackUserToCacheResp") - proto.RegisterType((*ReduceBlackUserFromCacheReq)(nil), "cache.ReduceBlackUserFromCacheReq") - proto.RegisterType((*ReduceBlackUserFromCacheResp)(nil), "cache.ReduceBlackUserFromCacheResp") + proto.RegisterType((*DelBlackIDListFromCacheReq)(nil), "cache.DelBlackIDListFromCacheReq") + proto.RegisterType((*DelBlackIDListFromCacheResp)(nil), "cache.DelBlackIDListFromCacheResp") proto.RegisterType((*GetGroupMemberIDListFromCacheReq)(nil), "cache.GetGroupMemberIDListFromCacheReq") proto.RegisterType((*GetGroupMemberIDListFromCacheResp)(nil), "cache.GetGroupMemberIDListFromCacheResp") - proto.RegisterType((*AddGroupMemberToCacheReq)(nil), "cache.AddGroupMemberToCacheReq") - proto.RegisterType((*AddGroupMemberToCacheResp)(nil), "cache.AddGroupMemberToCacheResp") - proto.RegisterType((*ReduceGroupMemberFromCacheReq)(nil), "cache.ReduceGroupMemberFromCacheReq") - proto.RegisterType((*ReduceGroupMemberFromCacheResp)(nil), "cache.ReduceGroupMemberFromCacheResp") + proto.RegisterType((*DelGroupMemberIDListFromCacheReq)(nil), "cache.DelGroupMemberIDListFromCacheReq") + proto.RegisterType((*DelGroupMemberIDListFromCacheResp)(nil), "cache.DelGroupMemberIDListFromCacheResp") } // Reference imports to suppress errors if they are not otherwise used. @@ -1111,21 +625,18 @@ const _ = grpc.SupportPackageIsVersion4 // Client API for Cache service type CacheClient interface { - // userInfo - GetUserInfoFromCache(ctx context.Context, in *GetUserInfoFromCacheReq, opts ...grpc.CallOption) (*GetUserInfoFromCacheResp, error) - UpdateUserInfoToCache(ctx context.Context, in *UpdateUserInfoToCacheReq, opts ...grpc.CallOption) (*UpdateUserInfoToCacheResp, error) // friendInfo GetFriendIDListFromCache(ctx context.Context, in *GetFriendIDListFromCacheReq, opts ...grpc.CallOption) (*GetFriendIDListFromCacheResp, error) - AddFriendToCache(ctx context.Context, in *AddFriendToCacheReq, opts ...grpc.CallOption) (*AddFriendToCacheResp, error) - ReduceFriendFromCache(ctx context.Context, in *ReduceFriendFromCacheReq, opts ...grpc.CallOption) (*ReduceFriendFromCacheResp, error) + // for dtm + DelFriendIDListFromCache(ctx context.Context, in *DelFriendIDListFromCacheReq, opts ...grpc.CallOption) (*DelFriendIDListFromCacheResp, error) // blackList GetBlackIDListFromCache(ctx context.Context, in *GetBlackIDListFromCacheReq, opts ...grpc.CallOption) (*GetBlackIDListFromCacheResp, error) - AddBlackUserToCache(ctx context.Context, in *AddBlackUserToCacheReq, opts ...grpc.CallOption) (*AddBlackUserToCacheResp, error) - ReduceBlackUserFromCache(ctx context.Context, in *ReduceBlackUserFromCacheReq, opts ...grpc.CallOption) (*ReduceBlackUserFromCacheResp, error) + // for dtm + DelBlackIDListFromCache(ctx context.Context, in *DelBlackIDListFromCacheReq, opts ...grpc.CallOption) (*DelBlackIDListFromCacheResp, error) // group GetGroupMemberIDListFromCache(ctx context.Context, in *GetGroupMemberIDListFromCacheReq, opts ...grpc.CallOption) (*GetGroupMemberIDListFromCacheResp, error) - AddGroupMemberToCache(ctx context.Context, in *AddGroupMemberToCacheReq, opts ...grpc.CallOption) (*AddGroupMemberToCacheResp, error) - ReduceGroupMemberFromCache(ctx context.Context, in *ReduceGroupMemberFromCacheReq, opts ...grpc.CallOption) (*ReduceGroupMemberFromCacheResp, error) + // for dtm + DelGroupMemberIDListFromCache(ctx context.Context, in *DelGroupMemberIDListFromCacheReq, opts ...grpc.CallOption) (*DelGroupMemberIDListFromCacheResp, error) } type cacheClient struct { @@ -1136,24 +647,6 @@ func NewCacheClient(cc *grpc.ClientConn) CacheClient { return &cacheClient{cc} } -func (c *cacheClient) GetUserInfoFromCache(ctx context.Context, in *GetUserInfoFromCacheReq, opts ...grpc.CallOption) (*GetUserInfoFromCacheResp, error) { - out := new(GetUserInfoFromCacheResp) - err := grpc.Invoke(ctx, "/cache.cache/GetUserInfoFromCache", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *cacheClient) UpdateUserInfoToCache(ctx context.Context, in *UpdateUserInfoToCacheReq, opts ...grpc.CallOption) (*UpdateUserInfoToCacheResp, error) { - out := new(UpdateUserInfoToCacheResp) - err := grpc.Invoke(ctx, "/cache.cache/UpdateUserInfoToCache", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - func (c *cacheClient) GetFriendIDListFromCache(ctx context.Context, in *GetFriendIDListFromCacheReq, opts ...grpc.CallOption) (*GetFriendIDListFromCacheResp, error) { out := new(GetFriendIDListFromCacheResp) err := grpc.Invoke(ctx, "/cache.cache/GetFriendIDListFromCache", in, out, c.cc, opts...) @@ -1163,18 +656,9 @@ func (c *cacheClient) GetFriendIDListFromCache(ctx context.Context, in *GetFrien return out, nil } -func (c *cacheClient) AddFriendToCache(ctx context.Context, in *AddFriendToCacheReq, opts ...grpc.CallOption) (*AddFriendToCacheResp, error) { - out := new(AddFriendToCacheResp) - err := grpc.Invoke(ctx, "/cache.cache/AddFriendToCache", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *cacheClient) ReduceFriendFromCache(ctx context.Context, in *ReduceFriendFromCacheReq, opts ...grpc.CallOption) (*ReduceFriendFromCacheResp, error) { - out := new(ReduceFriendFromCacheResp) - err := grpc.Invoke(ctx, "/cache.cache/ReduceFriendFromCache", in, out, c.cc, opts...) +func (c *cacheClient) DelFriendIDListFromCache(ctx context.Context, in *DelFriendIDListFromCacheReq, opts ...grpc.CallOption) (*DelFriendIDListFromCacheResp, error) { + out := new(DelFriendIDListFromCacheResp) + err := grpc.Invoke(ctx, "/cache.cache/DelFriendIDListFromCache", in, out, c.cc, opts...) if err != nil { return nil, err } @@ -1190,18 +674,9 @@ func (c *cacheClient) GetBlackIDListFromCache(ctx context.Context, in *GetBlackI return out, nil } -func (c *cacheClient) AddBlackUserToCache(ctx context.Context, in *AddBlackUserToCacheReq, opts ...grpc.CallOption) (*AddBlackUserToCacheResp, error) { - out := new(AddBlackUserToCacheResp) - err := grpc.Invoke(ctx, "/cache.cache/AddBlackUserToCache", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *cacheClient) ReduceBlackUserFromCache(ctx context.Context, in *ReduceBlackUserFromCacheReq, opts ...grpc.CallOption) (*ReduceBlackUserFromCacheResp, error) { - out := new(ReduceBlackUserFromCacheResp) - err := grpc.Invoke(ctx, "/cache.cache/ReduceBlackUserFromCache", in, out, c.cc, opts...) +func (c *cacheClient) DelBlackIDListFromCache(ctx context.Context, in *DelBlackIDListFromCacheReq, opts ...grpc.CallOption) (*DelBlackIDListFromCacheResp, error) { + out := new(DelBlackIDListFromCacheResp) + err := grpc.Invoke(ctx, "/cache.cache/DelBlackIDListFromCache", in, out, c.cc, opts...) if err != nil { return nil, err } @@ -1217,18 +692,9 @@ func (c *cacheClient) GetGroupMemberIDListFromCache(ctx context.Context, in *Get return out, nil } -func (c *cacheClient) AddGroupMemberToCache(ctx context.Context, in *AddGroupMemberToCacheReq, opts ...grpc.CallOption) (*AddGroupMemberToCacheResp, error) { - out := new(AddGroupMemberToCacheResp) - err := grpc.Invoke(ctx, "/cache.cache/AddGroupMemberToCache", in, out, c.cc, opts...) - if err != nil { - return nil, err - } - return out, nil -} - -func (c *cacheClient) ReduceGroupMemberFromCache(ctx context.Context, in *ReduceGroupMemberFromCacheReq, opts ...grpc.CallOption) (*ReduceGroupMemberFromCacheResp, error) { - out := new(ReduceGroupMemberFromCacheResp) - err := grpc.Invoke(ctx, "/cache.cache/ReduceGroupMemberFromCache", in, out, c.cc, opts...) +func (c *cacheClient) DelGroupMemberIDListFromCache(ctx context.Context, in *DelGroupMemberIDListFromCacheReq, opts ...grpc.CallOption) (*DelGroupMemberIDListFromCacheResp, error) { + out := new(DelGroupMemberIDListFromCacheResp) + err := grpc.Invoke(ctx, "/cache.cache/DelGroupMemberIDListFromCache", in, out, c.cc, opts...) if err != nil { return nil, err } @@ -1238,63 +704,24 @@ func (c *cacheClient) ReduceGroupMemberFromCache(ctx context.Context, in *Reduce // Server API for Cache service type CacheServer interface { - // userInfo - GetUserInfoFromCache(context.Context, *GetUserInfoFromCacheReq) (*GetUserInfoFromCacheResp, error) - UpdateUserInfoToCache(context.Context, *UpdateUserInfoToCacheReq) (*UpdateUserInfoToCacheResp, error) // friendInfo GetFriendIDListFromCache(context.Context, *GetFriendIDListFromCacheReq) (*GetFriendIDListFromCacheResp, error) - AddFriendToCache(context.Context, *AddFriendToCacheReq) (*AddFriendToCacheResp, error) - ReduceFriendFromCache(context.Context, *ReduceFriendFromCacheReq) (*ReduceFriendFromCacheResp, error) + // for dtm + DelFriendIDListFromCache(context.Context, *DelFriendIDListFromCacheReq) (*DelFriendIDListFromCacheResp, error) // blackList GetBlackIDListFromCache(context.Context, *GetBlackIDListFromCacheReq) (*GetBlackIDListFromCacheResp, error) - AddBlackUserToCache(context.Context, *AddBlackUserToCacheReq) (*AddBlackUserToCacheResp, error) - ReduceBlackUserFromCache(context.Context, *ReduceBlackUserFromCacheReq) (*ReduceBlackUserFromCacheResp, error) + // for dtm + DelBlackIDListFromCache(context.Context, *DelBlackIDListFromCacheReq) (*DelBlackIDListFromCacheResp, error) // group GetGroupMemberIDListFromCache(context.Context, *GetGroupMemberIDListFromCacheReq) (*GetGroupMemberIDListFromCacheResp, error) - AddGroupMemberToCache(context.Context, *AddGroupMemberToCacheReq) (*AddGroupMemberToCacheResp, error) - ReduceGroupMemberFromCache(context.Context, *ReduceGroupMemberFromCacheReq) (*ReduceGroupMemberFromCacheResp, error) + // for dtm + DelGroupMemberIDListFromCache(context.Context, *DelGroupMemberIDListFromCacheReq) (*DelGroupMemberIDListFromCacheResp, error) } func RegisterCacheServer(s *grpc.Server, srv CacheServer) { s.RegisterService(&_Cache_serviceDesc, srv) } -func _Cache_GetUserInfoFromCache_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(GetUserInfoFromCacheReq) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(CacheServer).GetUserInfoFromCache(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/cache.cache/GetUserInfoFromCache", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(CacheServer).GetUserInfoFromCache(ctx, req.(*GetUserInfoFromCacheReq)) - } - return interceptor(ctx, in, info, handler) -} - -func _Cache_UpdateUserInfoToCache_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(UpdateUserInfoToCacheReq) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(CacheServer).UpdateUserInfoToCache(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/cache.cache/UpdateUserInfoToCache", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(CacheServer).UpdateUserInfoToCache(ctx, req.(*UpdateUserInfoToCacheReq)) - } - return interceptor(ctx, in, info, handler) -} - func _Cache_GetFriendIDListFromCache_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(GetFriendIDListFromCacheReq) if err := dec(in); err != nil { @@ -1313,38 +740,20 @@ func _Cache_GetFriendIDListFromCache_Handler(srv interface{}, ctx context.Contex return interceptor(ctx, in, info, handler) } -func _Cache_AddFriendToCache_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AddFriendToCacheReq) +func _Cache_DelFriendIDListFromCache_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DelFriendIDListFromCacheReq) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(CacheServer).AddFriendToCache(ctx, in) + return srv.(CacheServer).DelFriendIDListFromCache(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/cache.cache/AddFriendToCache", + FullMethod: "/cache.cache/DelFriendIDListFromCache", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(CacheServer).AddFriendToCache(ctx, req.(*AddFriendToCacheReq)) - } - return interceptor(ctx, in, info, handler) -} - -func _Cache_ReduceFriendFromCache_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ReduceFriendFromCacheReq) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(CacheServer).ReduceFriendFromCache(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/cache.cache/ReduceFriendFromCache", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(CacheServer).ReduceFriendFromCache(ctx, req.(*ReduceFriendFromCacheReq)) + return srv.(CacheServer).DelFriendIDListFromCache(ctx, req.(*DelFriendIDListFromCacheReq)) } return interceptor(ctx, in, info, handler) } @@ -1367,38 +776,20 @@ func _Cache_GetBlackIDListFromCache_Handler(srv interface{}, ctx context.Context return interceptor(ctx, in, info, handler) } -func _Cache_AddBlackUserToCache_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AddBlackUserToCacheReq) +func _Cache_DelBlackIDListFromCache_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DelBlackIDListFromCacheReq) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(CacheServer).AddBlackUserToCache(ctx, in) + return srv.(CacheServer).DelBlackIDListFromCache(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/cache.cache/AddBlackUserToCache", + FullMethod: "/cache.cache/DelBlackIDListFromCache", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(CacheServer).AddBlackUserToCache(ctx, req.(*AddBlackUserToCacheReq)) - } - return interceptor(ctx, in, info, handler) -} - -func _Cache_ReduceBlackUserFromCache_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ReduceBlackUserFromCacheReq) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(CacheServer).ReduceBlackUserFromCache(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/cache.cache/ReduceBlackUserFromCache", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(CacheServer).ReduceBlackUserFromCache(ctx, req.(*ReduceBlackUserFromCacheReq)) + return srv.(CacheServer).DelBlackIDListFromCache(ctx, req.(*DelBlackIDListFromCacheReq)) } return interceptor(ctx, in, info, handler) } @@ -1421,38 +812,20 @@ func _Cache_GetGroupMemberIDListFromCache_Handler(srv interface{}, ctx context.C return interceptor(ctx, in, info, handler) } -func _Cache_AddGroupMemberToCache_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(AddGroupMemberToCacheReq) +func _Cache_DelGroupMemberIDListFromCache_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DelGroupMemberIDListFromCacheReq) if err := dec(in); err != nil { return nil, err } if interceptor == nil { - return srv.(CacheServer).AddGroupMemberToCache(ctx, in) + return srv.(CacheServer).DelGroupMemberIDListFromCache(ctx, in) } info := &grpc.UnaryServerInfo{ Server: srv, - FullMethod: "/cache.cache/AddGroupMemberToCache", + FullMethod: "/cache.cache/DelGroupMemberIDListFromCache", } handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(CacheServer).AddGroupMemberToCache(ctx, req.(*AddGroupMemberToCacheReq)) - } - return interceptor(ctx, in, info, handler) -} - -func _Cache_ReduceGroupMemberFromCache_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { - in := new(ReduceGroupMemberFromCacheReq) - if err := dec(in); err != nil { - return nil, err - } - if interceptor == nil { - return srv.(CacheServer).ReduceGroupMemberFromCache(ctx, in) - } - info := &grpc.UnaryServerInfo{ - Server: srv, - FullMethod: "/cache.cache/ReduceGroupMemberFromCache", - } - handler := func(ctx context.Context, req interface{}) (interface{}, error) { - return srv.(CacheServer).ReduceGroupMemberFromCache(ctx, req.(*ReduceGroupMemberFromCacheReq)) + return srv.(CacheServer).DelGroupMemberIDListFromCache(ctx, req.(*DelGroupMemberIDListFromCacheReq)) } return interceptor(ctx, in, info, handler) } @@ -1461,104 +834,67 @@ var _Cache_serviceDesc = grpc.ServiceDesc{ ServiceName: "cache.cache", HandlerType: (*CacheServer)(nil), Methods: []grpc.MethodDesc{ - { - MethodName: "GetUserInfoFromCache", - Handler: _Cache_GetUserInfoFromCache_Handler, - }, - { - MethodName: "UpdateUserInfoToCache", - Handler: _Cache_UpdateUserInfoToCache_Handler, - }, { MethodName: "GetFriendIDListFromCache", Handler: _Cache_GetFriendIDListFromCache_Handler, }, { - MethodName: "AddFriendToCache", - Handler: _Cache_AddFriendToCache_Handler, - }, - { - MethodName: "ReduceFriendFromCache", - Handler: _Cache_ReduceFriendFromCache_Handler, + MethodName: "DelFriendIDListFromCache", + Handler: _Cache_DelFriendIDListFromCache_Handler, }, { MethodName: "GetBlackIDListFromCache", Handler: _Cache_GetBlackIDListFromCache_Handler, }, { - MethodName: "AddBlackUserToCache", - Handler: _Cache_AddBlackUserToCache_Handler, - }, - { - MethodName: "ReduceBlackUserFromCache", - Handler: _Cache_ReduceBlackUserFromCache_Handler, + MethodName: "DelBlackIDListFromCache", + Handler: _Cache_DelBlackIDListFromCache_Handler, }, { MethodName: "GetGroupMemberIDListFromCache", Handler: _Cache_GetGroupMemberIDListFromCache_Handler, }, { - MethodName: "AddGroupMemberToCache", - Handler: _Cache_AddGroupMemberToCache_Handler, - }, - { - MethodName: "ReduceGroupMemberFromCache", - Handler: _Cache_ReduceGroupMemberFromCache_Handler, + MethodName: "DelGroupMemberIDListFromCache", + Handler: _Cache_DelGroupMemberIDListFromCache_Handler, }, }, Streams: []grpc.StreamDesc{}, Metadata: "cache/cache.proto", } -func init() { proto.RegisterFile("cache/cache.proto", fileDescriptor_cache_cf8751e0f76be356) } - -var fileDescriptor_cache_cf8751e0f76be356 = []byte{ - // 751 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x57, 0x6f, 0x4f, 0x13, 0x4f, - 0x10, 0xce, 0x95, 0xc0, 0x0f, 0xa6, 0x3f, 0xa3, 0xac, 0x08, 0xc7, 0x16, 0xea, 0x71, 0x6a, 0xec, - 0xab, 0x36, 0xe2, 0x4b, 0x13, 0x0d, 0x7f, 0x42, 0xd3, 0x08, 0x18, 0x4f, 0x90, 0x04, 0x13, 0xeb, - 0xd1, 0x5b, 0xb0, 0xa9, 0xed, 0x2d, 0xbb, 0x57, 0x88, 0x31, 0x7e, 0x05, 0x3f, 0x84, 0x9f, 0xd4, - 0x74, 0xf7, 0xfe, 0x73, 0x7b, 0x3d, 0x0e, 0x7d, 0x73, 0xc9, 0xee, 0xce, 0x3d, 0x33, 0xcf, 0x3e, - 0x73, 0x33, 0x73, 0xb0, 0xd8, 0xb3, 0x7b, 0x5f, 0x49, 0x4b, 0x3c, 0x9b, 0x94, 0xb9, 0x9e, 0x8b, - 0x66, 0xc5, 0x02, 0x6f, 0xbc, 0xa3, 0x64, 0xd4, 0xed, 0x1c, 0xb4, 0xe8, 0xe0, 0xa2, 0x25, 0x4e, - 0x5a, 0xdc, 0x19, 0x74, 0xaf, 0x79, 0xeb, 0x9a, 0x4b, 0x4b, 0xf3, 0x35, 0xc0, 0x8e, 0x3b, 0x1c, - 0xba, 0x23, 0x8b, 0x70, 0x8a, 0x74, 0xf8, 0x8f, 0x30, 0xb6, 0xe3, 0x3a, 0x44, 0xd7, 0x0c, 0xad, - 0x31, 0x6b, 0x05, 0x4b, 0xb4, 0x0c, 0x73, 0x84, 0xb1, 0x03, 0x7e, 0xa1, 0x57, 0x0c, 0xad, 0xb1, - 0x60, 0xf9, 0x2b, 0xf3, 0x13, 0xac, 0xb4, 0x89, 0x77, 0xcc, 0x09, 0xeb, 0x8c, 0xce, 0xdd, 0x3d, - 0xe6, 0x0e, 0x77, 0x26, 0xae, 0x2d, 0x72, 0x89, 0xea, 0x00, 0xe3, 0xc9, 0xfe, 0xee, 0x7e, 0x9f, - 0x7b, 0xba, 0x66, 0xcc, 0x34, 0x16, 0xac, 0xd8, 0x0e, 0x32, 0xa0, 0xea, 0x52, 0xc2, 0x6c, 0xaf, - 0xef, 0x8e, 0x3a, 0xbb, 0x3e, 0x6e, 0x7c, 0xcb, 0xfc, 0xa5, 0x81, 0x9e, 0x8d, 0xce, 0x29, 0x7a, - 0x01, 0xd0, 0x0b, 0x23, 0x17, 0xe1, 0x56, 0x37, 0x17, 0x9b, 0xf2, 0x16, 0x22, 0x4a, 0x56, 0xcc, - 0x08, 0xbd, 0x81, 0xff, 0xc7, 0x3e, 0x96, 0x88, 0xa9, 0x62, 0xcc, 0x34, 0xaa, 0x9b, 0xb5, 0x26, - 0x27, 0xec, 0x8a, 0xb0, 0xae, 0x4d, 0xfb, 0x5d, 0x6a, 0x33, 0x7b, 0xc8, 0x9b, 0x81, 0x4b, 0x2b, - 0xf1, 0x82, 0xf9, 0x13, 0xf4, 0x63, 0xea, 0xd8, 0x1e, 0x09, 0xce, 0x8f, 0xdc, 0x90, 0x6e, 0x1a, - 0x5c, 0xbb, 0x25, 0x78, 0x81, 0xfb, 0x38, 0x84, 0x55, 0x85, 0xfb, 0x52, 0xf7, 0x61, 0x9e, 0x40, - 0xad, 0x4d, 0xbc, 0x3d, 0xd6, 0x27, 0x23, 0x47, 0x8a, 0x92, 0x10, 0x70, 0x19, 0xe6, 0xa4, 0x5c, - 0x02, 0x6d, 0xc1, 0xf2, 0x57, 0x05, 0x02, 0xbd, 0x84, 0x35, 0x35, 0x30, 0xa7, 0x53, 0x53, 0x23, - 0xc9, 0xa5, 0x52, 0x84, 0xcb, 0x00, 0x1e, 0x6e, 0x39, 0x8e, 0x74, 0x19, 0x53, 0x45, 0xc5, 0x01, - 0xc3, 0xfc, 0xb9, 0x1f, 0x9e, 0x4f, 0x20, 0x5c, 0xa7, 0xf9, 0xcd, 0xdc, 0xe4, 0xd7, 0x81, 0xa5, - 0x9b, 0xce, 0xca, 0x69, 0x40, 0x41, 0xb7, 0x88, 0x33, 0xee, 0x11, 0x89, 0x56, 0x48, 0x80, 0xbb, - 0x05, 0x7f, 0x08, 0xab, 0x0a, 0x8f, 0xe5, 0x18, 0x7c, 0x04, 0xdc, 0x26, 0xde, 0xf6, 0x37, 0xbb, - 0x37, 0xf8, 0xab, 0x49, 0x44, 0x45, 0x76, 0x66, 0xe3, 0xfe, 0x9b, 0x1c, 0xf2, 0x60, 0x79, 0xcb, - 0x71, 0x84, 0xc7, 0xc9, 0x17, 0x56, 0x20, 0x8d, 0x0c, 0xa8, 0x9e, 0x05, 0xe6, 0x11, 0x8b, 0xd8, - 0x56, 0x01, 0x3d, 0xf6, 0x61, 0x25, 0xd3, 0x6b, 0x39, 0x35, 0xbe, 0x43, 0x4d, 0xaa, 0x1b, 0x02, - 0x16, 0x95, 0xe3, 0xce, 0x44, 0xde, 0xc3, 0x9a, 0xda, 0x75, 0x39, 0x36, 0x9f, 0xc1, 0x68, 0x13, - 0xaf, 0xcd, 0xdc, 0x31, 0x3d, 0x20, 0xc3, 0xb3, 0x40, 0xdc, 0x04, 0xa5, 0x54, 0x60, 0xda, 0x8d, - 0xc0, 0x26, 0x6d, 0xed, 0x62, 0x02, 0x11, 0x12, 0x0b, 0x96, 0xe6, 0x15, 0x6c, 0x4c, 0xc1, 0x2f, - 0xd7, 0x69, 0x92, 0xc9, 0x59, 0x49, 0x27, 0xa7, 0x79, 0x05, 0xfa, 0x96, 0xe3, 0xc4, 0xfc, 0xc6, - 0x72, 0x6d, 0x5a, 0x62, 0x2b, 0xd9, 0x14, 0xfb, 0xf6, 0x15, 0x7e, 0xcb, 0xe9, 0xf3, 0x03, 0xd6, - 0xa5, 0xe4, 0x31, 0xc8, 0x5b, 0x0d, 0x01, 0x77, 0x21, 0xf3, 0x01, 0xea, 0x79, 0xce, 0x4b, 0x31, - 0xda, 0xfc, 0x3d, 0x0f, 0x72, 0x7a, 0x42, 0x27, 0xb0, 0x94, 0x35, 0x7c, 0xa0, 0xba, 0x0f, 0xa0, - 0x98, 0x7b, 0xf0, 0xe3, 0xdc, 0x73, 0x4e, 0xd1, 0x29, 0x3c, 0xca, 0x6c, 0xe3, 0x28, 0x78, 0x53, - 0x35, 0x63, 0x60, 0x23, 0xdf, 0x80, 0x53, 0xd4, 0x13, 0x13, 0x53, 0x66, 0xe7, 0x45, 0x66, 0x14, - 0x98, 0xaa, 0xe7, 0xe3, 0x27, 0x53, 0x6d, 0x38, 0x45, 0x6f, 0xe1, 0x41, 0xba, 0xfd, 0x21, 0xec, - 0xbf, 0x98, 0xd1, 0x84, 0x71, 0x4d, 0x79, 0x26, 0x6f, 0x23, 0xb3, 0x1d, 0x85, 0xb7, 0xa1, 0x6a, - 0x8f, 0xe1, 0x6d, 0xa8, 0xbb, 0xd9, 0x17, 0x31, 0x9d, 0x66, 0xb5, 0x10, 0xb4, 0x11, 0x11, 0x55, - 0xb4, 0x2e, 0x6c, 0x4e, 0x33, 0xe1, 0x14, 0x1d, 0x89, 0xb1, 0x23, 0x5d, 0xbc, 0xd1, 0x7a, 0xc4, - 0x38, 0xa3, 0x9d, 0xe0, 0x7a, 0xde, 0xb1, 0x54, 0x51, 0x55, 0x49, 0x43, 0x15, 0x73, 0xaa, 0x7c, - 0xa8, 0x62, 0x6e, 0x39, 0x66, 0xb0, 0x9e, 0x5b, 0xfb, 0xd0, 0xf3, 0x88, 0x7f, 0x6e, 0x05, 0xc6, - 0x8d, 0x62, 0x86, 0x52, 0xec, 0xcc, 0xfa, 0x13, 0x8a, 0xad, 0xaa, 0x8a, 0xa1, 0xd8, 0xea, 0xf2, - 0xd5, 0x07, 0xac, 0x2e, 0x07, 0xe8, 0x69, 0xe2, 0x4a, 0x14, 0xe5, 0x0a, 0x3f, 0x2b, 0x60, 0xc5, - 0xe9, 0xf6, 0xfd, 0xd3, 0x7b, 0x4d, 0xf9, 0xc3, 0xf5, 0x4a, 0x3c, 0xcf, 0xe6, 0xc4, 0xdf, 0xd4, - 0xcb, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xdf, 0x94, 0x59, 0x33, 0x8c, 0x0d, 0x00, 0x00, +func init() { proto.RegisterFile("cache/cache.proto", fileDescriptor_cache_dd6bac081ee50bd6) } + +var fileDescriptor_cache_dd6bac081ee50bd6 = []byte{ + // 469 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0xcd, 0x8f, 0x93, 0x40, + 0x14, 0x0f, 0xab, 0xbb, 0xa6, 0x6f, 0x63, 0xcc, 0xce, 0x41, 0x09, 0xae, 0x06, 0xf0, 0x20, 0xa7, + 0x12, 0xd7, 0xa3, 0x89, 0x87, 0x2d, 0x59, 0x42, 0x62, 0xa3, 0x72, 0xa8, 0x89, 0x07, 0xd7, 0x2e, + 0x7d, 0xa9, 0x4d, 0x81, 0x99, 0x9d, 0x61, 0xed, 0x5f, 0x6f, 0x62, 0x66, 0xa0, 0x94, 0xa2, 0x03, + 0x4d, 0xd3, 0x5e, 0x48, 0x1e, 0x3c, 0x7e, 0x1f, 0xf3, 0x3e, 0x06, 0x2e, 0x92, 0x69, 0xf2, 0x0b, + 0x7d, 0xf5, 0x1c, 0x32, 0x4e, 0x0b, 0x4a, 0x4e, 0x55, 0x60, 0x39, 0x9f, 0x19, 0xe6, 0xb7, 0xd1, + 0xd8, 0x67, 0xcb, 0xb9, 0xaf, 0xbe, 0xf8, 0x62, 0xb6, 0xbc, 0x5d, 0x09, 0x7f, 0x25, 0xca, 0x4c, + 0xf7, 0x23, 0xc0, 0x88, 0x66, 0x19, 0xcd, 0x63, 0x14, 0x8c, 0x98, 0xf0, 0x04, 0x39, 0x1f, 0xd1, + 0x19, 0x9a, 0x86, 0x6d, 0x78, 0xa7, 0xf1, 0x3a, 0x24, 0xcf, 0xe1, 0x0c, 0x39, 0x1f, 0x8b, 0xb9, + 0x79, 0x62, 0x1b, 0xde, 0x20, 0xae, 0x22, 0xf7, 0x1b, 0xbc, 0x0c, 0xb1, 0xb8, 0xe1, 0x0b, 0xcc, + 0x67, 0x51, 0xf0, 0x69, 0x21, 0x8a, 0x1b, 0x4e, 0xb3, 0x91, 0xa4, 0x8f, 0xf1, 0x5e, 0xfe, 0xf6, + 0x20, 0x90, 0x47, 0x81, 0xc2, 0x1b, 0xc4, 0x55, 0x44, 0x6c, 0x38, 0xa7, 0x0c, 0xf9, 0xb4, 0x58, + 0xd0, 0x3c, 0x0a, 0x2a, 0xcc, 0xe6, 0x2b, 0xf7, 0x1e, 0x2e, 0xf5, 0xc0, 0x82, 0x91, 0xd7, 0x00, + 0x25, 0x96, 0xfc, 0x64, 0x1a, 0xf6, 0x23, 0x6f, 0x10, 0x37, 0xde, 0x90, 0x77, 0x00, 0x49, 0x6d, + 0x4c, 0x11, 0x9c, 0x5f, 0x5d, 0x0c, 0xcb, 0x43, 0xda, 0x38, 0x8e, 0x1b, 0x49, 0xd2, 0x4b, 0x80, + 0xe9, 0x11, 0xbc, 0x7c, 0x85, 0x4b, 0x3d, 0xb0, 0x60, 0x2d, 0xad, 0xc6, 0x2e, 0x5a, 0x27, 0x60, + 0x85, 0x58, 0x5c, 0xa7, 0xd3, 0x64, 0x79, 0x50, 0xa9, 0x4c, 0xd5, 0xf3, 0xff, 0xb8, 0xc7, 0x39, + 0xf5, 0x09, 0x58, 0x01, 0xa6, 0x87, 0x77, 0xf2, 0x45, 0x55, 0x53, 0xeb, 0x64, 0x8f, 0x33, 0xff, + 0x01, 0x76, 0x88, 0x45, 0xc8, 0xe9, 0x03, 0x1b, 0x63, 0x76, 0xb7, 0x36, 0xbd, 0xa5, 0xb7, 0xa5, + 0xcb, 0xf8, 0x47, 0x97, 0x9c, 0xb1, 0xb9, 0x84, 0xa8, 0x55, 0xaf, 0x43, 0xf7, 0x37, 0x38, 0x3d, + 0xf8, 0x7b, 0xe9, 0x6e, 0x15, 0xed, 0xa4, 0x5d, 0x34, 0xe9, 0x2b, 0xc0, 0xb4, 0xdb, 0x57, 0x43, + 0xb5, 0xb1, 0xa5, 0x7a, 0x87, 0x4a, 0x4c, 0xc0, 0xe9, 0xc1, 0xdf, 0xcb, 0xd7, 0xd5, 0x9f, 0xc7, + 0x50, 0x2e, 0x3a, 0x92, 0x80, 0xa9, 0x5b, 0x16, 0xc4, 0xad, 0x40, 0x3a, 0xd6, 0x94, 0xf5, 0xa6, + 0x37, 0x47, 0x30, 0x49, 0xa2, 0x9b, 0xe2, 0x9a, 0xa4, 0x63, 0x7f, 0xd4, 0x24, 0x9d, 0xab, 0xe0, + 0x27, 0xbc, 0xd0, 0xcc, 0x1f, 0x71, 0x36, 0x22, 0x35, 0xd3, 0x62, 0xb9, 0x7d, 0x29, 0x25, 0x83, + 0x66, 0x2e, 0x6a, 0x06, 0xfd, 0x3c, 0x5a, 0x6e, 0x5f, 0x8a, 0x60, 0x84, 0xc3, 0xab, 0xce, 0x3e, + 0x26, 0x6f, 0x37, 0x32, 0x3b, 0xbb, 0xce, 0xf2, 0x76, 0x4b, 0x2c, 0x39, 0x3b, 0x7b, 0xac, 0xe6, + 0xec, 0xeb, 0xf4, 0x9a, 0xb3, 0xb7, 0x65, 0xaf, 0x9f, 0x7d, 0x7f, 0x3a, 0x2c, 0xaf, 0xdd, 0x0f, + 0xea, 0x79, 0x77, 0xa6, 0xee, 0xd4, 0xf7, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0xbb, 0xd1, 0x83, + 0x35, 0x92, 0x07, 0x00, 0x00, } diff --git a/pkg/proto/cache/cache.proto b/pkg/proto/cache/cache.proto index b452ac1f1..7e1eeabdf 100644 --- a/pkg/proto/cache/cache.proto +++ b/pkg/proto/cache/cache.proto @@ -8,26 +8,6 @@ message CommonResp{ string errMsg = 2; } -message GetUserInfoFromCacheReq{ - repeated string userIDList = 1; - string operationID = 2; -} - -message GetUserInfoFromCacheResp{ - CommonResp commonResp = 1; - repeated server_api_params.UserInfo userInfoList = 2; -} - - -message UpdateUserInfoToCacheReq{ - repeated server_api_params.UserInfo userInfoList = 1; - string operationID = 2; -} - -message UpdateUserInfoToCacheResp{ - CommonResp commonResp = 1; -} - message GetFriendIDListFromCacheReq { string userID = 1; string operationID = 2; @@ -38,24 +18,13 @@ message GetFriendIDListFromCacheResp { CommonResp commonResp = 2; } -message AddFriendToCacheReq { - string userID = 1; - string friendID = 2; - string operationID = 3; -} - -message AddFriendToCacheResp { - CommonResp commonResp = 1; -} - -message ReduceFriendFromCacheReq { - string userID = 1; - string friendID = 2; - string operationID = 3; +message DelFriendIDListFromCacheReq { + string userID = 1; + string operationID = 2; } -message ReduceFriendFromCacheResp { - CommonResp commonResp = 1; +message DelFriendIDListFromCacheResp { + CommonResp commonResp = 1; } message GetBlackIDListFromCacheReq { @@ -68,23 +37,12 @@ message GetBlackIDListFromCacheResp { CommonResp commonResp = 2; } -message AddBlackUserToCacheReq { +message DelBlackIDListFromCacheReq { string userID = 1; - string blackUserID = 2; - string operationID = 3; -} - -message AddBlackUserToCacheResp { - CommonResp commonResp = 1; -} - -message ReduceBlackUserFromCacheReq { - string userID = 1; - string blackUserID = 2; - string operationID = 3; + string operationID = 2; } -message ReduceBlackUserFromCacheResp { +message DelBlackIDListFromCacheResp { CommonResp commonResp = 1; } @@ -98,45 +56,34 @@ message GetGroupMemberIDListFromCacheResp { repeated string userIDList = 2; } -message AddGroupMemberToCacheReq { - repeated string userIDList = 1; - string groupID = 2; - string operationID = 3; -} - -message AddGroupMemberToCacheResp { - CommonResp commonResp = 1; -} - -message ReduceGroupMemberFromCacheReq { - repeated string userIDList = 1; - string groupID = 2; - string operationID = 3; +message DelGroupMemberIDListFromCacheReq { + string groupID = 1; + string operationID = 2; } -message ReduceGroupMemberFromCacheResp { +message DelGroupMemberIDListFromCacheResp { CommonResp commonResp = 1; } service cache{ - // userInfo - rpc GetUserInfoFromCache(GetUserInfoFromCacheReq) returns(GetUserInfoFromCacheResp); - rpc UpdateUserInfoToCache(UpdateUserInfoToCacheReq) returns(UpdateUserInfoToCacheResp); // friendInfo rpc GetFriendIDListFromCache(GetFriendIDListFromCacheReq) returns(GetFriendIDListFromCacheResp); - rpc AddFriendToCache(AddFriendToCacheReq) returns(AddFriendToCacheResp); - rpc ReduceFriendFromCache(ReduceFriendFromCacheReq) returns(ReduceFriendFromCacheResp); + + // for dtm + rpc DelFriendIDListFromCache(DelFriendIDListFromCacheReq) returns(DelFriendIDListFromCacheResp); // blackList rpc GetBlackIDListFromCache(GetBlackIDListFromCacheReq) returns(GetBlackIDListFromCacheResp); - rpc AddBlackUserToCache(AddBlackUserToCacheReq) returns(AddBlackUserToCacheResp); - rpc ReduceBlackUserFromCache(ReduceBlackUserFromCacheReq) returns(ReduceBlackUserFromCacheResp); + + // for dtm + rpc DelBlackIDListFromCache(DelBlackIDListFromCacheReq) returns (DelBlackIDListFromCacheResp); // group rpc GetGroupMemberIDListFromCache(GetGroupMemberIDListFromCacheReq) returns(GetGroupMemberIDListFromCacheResp); - rpc AddGroupMemberToCache(AddGroupMemberToCacheReq) returns(AddGroupMemberToCacheResp); - rpc ReduceGroupMemberFromCache(ReduceGroupMemberFromCacheReq) returns(ReduceGroupMemberFromCacheResp); + + // for dtm + rpc DelGroupMemberIDListFromCache(DelGroupMemberIDListFromCacheReq) returns(DelGroupMemberIDListFromCacheResp); } diff --git a/test/redis/cmd/main.go b/test/redis/cmd/main.go deleted file mode 100644 index ef38c17a2..000000000 --- a/test/redis/cmd/main.go +++ /dev/null @@ -1,94 +0,0 @@ -package main - -import ( - "Open_IM/pkg/common/config" - "Open_IM/pkg/common/db" - "Open_IM/pkg/proto/user" - "database/sql" - "fmt" - "github.com/dtm-labs/rockscache" - "github.com/gin-gonic/gin" - go_redis "github.com/go-redis/redis/v8" - "github.com/dtm-labs/dtmcli" - "github.com/dtm-labs/dtmgrpc" - "github.com/gogo/protobuf/proto" - "google.golang.org/protobuf/reflect/protoreflect" - - "github.com/lithammer/shortuuid" - "time" -) - -func main() { - rc := rockscache.NewClient(go_redis.NewClient(&go_redis.Options{ - Addr: "43.128.5.63:16379", - Password: "openIM", // no password set - DB: 3, // use default DB - PoolSize: 100, // 连接池大小 - }), rockscache.NewDefaultOptions()) - rc.Options.StrongConsistency = true - - //gid := dtmcli.MustGenGid(config.Config.Dtm.ServerURL) - // - //getGroupInfo := func()(string, error) { - // fmt.Println("start to fetch") - // time.Sleep(time.Second*5) - // fmt.Println("stop to fetch") - // return "value2312", nil - //} - // - //v, err := rc.Fetch("keyasd347", time.Second*120, getGroupInfo) - //fmt.Println("set success") - - - //gid := dtmcli.MustGenGid(config.Config.Dtm.ServerURL) - //msg := dtmcli.NewMsg(DtmServer, shortuuid.New()). - // Add(busi.Busi+"/SagaBTransIn", &TransReq{ Amount: 30 }) - // - //dtmcli.DB() - //time.Sleep(time.Second*12) - //v2, _ := rc.Fetch("keyasd347", time.Second*10, func()(string, error) { - // // fetch data from database or other sources - // return "value1", nil - //}) - - - - //fmt.Println(v, err) - //fmt.Println(v2) - //err = rc.TagAsDeleted("keyasd347") - //fmt.Println(err) -} - -func UpdateUserInfo(c *gin.Context) { - gid := dtmcli.MustGenGid(config.Config.Dtm.ServerURL) - var pb user.GetAllUserIDReq - msg := dtmgrpc.NewMsgGrpc(config.Config.Dtm.ServerURL, gid).Add("url1", &pb) - msg.DoAndSubmit("/QueryPreparedB", func(bb *dtmcli.BranchBarrier) error { - return bb.CallWithDB(db, func(tx *sql.Tx) error { - return UpdateInTx(tx, &DBRow{ - K: body["key"].(string), - V: body["value"].(string), - TimeCost: body["time_cost"].(string), - }) - }) - }) -})) - -} - -func GetUserInfo(c *gin.Context) { - // rpc logic - v2, _ := db.DB.Rc.Fetch("keyasd347", time.Second*10, func()(string, error) { - // fetch data from database or other sources - return "value1", nil - }) - c.JSON(200, map[string]interface{}{"s":v2}) -} - -// QueryPreparedB -func QueryPreparedB() { - app.GET(BusiAPI+"/QueryPreparedB", dtmutil.WrapHandler2(func(c *gin.Context) interface{} { - bb := MustBarrierFromGin(c) - return bb.QueryPrepared(dbGet()) - })) -} \ No newline at end of file