From 3fcc2c267815a107cd1e62cc74df50355bea7d02 Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Sat, 3 Sep 2022 15:48:45 +0800 Subject: [PATCH 1/3] cache for GetDefaultGatewayConn4Unique --- pkg/grpc-etcdv3/getcdv3/resolver.go | 33 +++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/pkg/grpc-etcdv3/getcdv3/resolver.go b/pkg/grpc-etcdv3/getcdv3/resolver.go index e77bb626b..878cabc64 100644 --- a/pkg/grpc-etcdv3/getcdv3/resolver.go +++ b/pkg/grpc-etcdv3/getcdv3/resolver.go @@ -6,7 +6,6 @@ import ( "Open_IM/pkg/utils" "context" "fmt" - "go.etcd.io/etcd/api/v3/mvccpb" clientv3 "go.etcd.io/etcd/client/v3" @@ -277,8 +276,38 @@ func (r *Resolver) watch(prefix string, addrList []resolver.Address) { } } +var Conn4UniqueList []*grpc.ClientConn +var Conn4UniqueListMtx sync.RWMutex +var IsUpdateStart bool +var IsUpdateStartMtx sync.RWMutex + func GetDefaultGatewayConn4Unique(schema, etcdaddr, operationID string) []*grpc.ClientConn { - grpcConns := getConn4Unique(schema, etcdaddr, config.Config.RpcRegisterName.OpenImRelayName) + IsUpdateStartMtx.Lock() + if IsUpdateStart == false { + Conn4UniqueList = getConn4Unique(schema, etcdaddr, config.Config.RpcRegisterName.OpenImRelayName) + go func() { + for { + select { + case <-time.After(time.Second * time.Duration(30)): + Conn4UniqueListMtx.Lock() + Conn4UniqueList = getConn4Unique(schema, etcdaddr, config.Config.RpcRegisterName.OpenImRelayName) + Conn4UniqueListMtx.Unlock() + } + } + }() + } + IsUpdateStart = true + IsUpdateStartMtx.Unlock() + + Conn4UniqueListMtx.Lock() + var clientConnList []*grpc.ClientConn + for _, v := range Conn4UniqueList { + clientConnList = append(clientConnList, v) + } + Conn4UniqueListMtx.Unlock() + + //grpcConns := getConn4Unique(schema, etcdaddr, config.Config.RpcRegisterName.OpenImRelayName) + grpcConns := clientConnList if len(grpcConns) > 0 { return grpcConns } From 6754fdb580907d96b55f7c0d01f45d6692027d93 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Wed, 7 Sep 2022 18:20:41 +0800 Subject: [PATCH 2/3] getui --- config/config.yaml | 2 ++ internal/push/getui/push.go | 16 ++++++++++------ pkg/common/config/config.go | 2 ++ 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/config/config.yaml b/config/config.yaml index 6e10a65b2..c738166fd 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -221,6 +221,8 @@ push: appKey: "" intent: "" enable: false + channelID: "" + channelName: "" fcm: #firebase cloud message 消息推送 serviceAccount: "openim-5c6c0-firebase-adminsdk-ppwol-8765884a78.json" #帐号文件,此处需要改修配置,并且这个文件放在 config目录下 enable: false diff --git a/internal/push/getui/push.go b/internal/push/getui/push.go index 7f7012bb2..27c107b8c 100644 --- a/internal/push/getui/push.go +++ b/internal/push/getui/push.go @@ -88,9 +88,11 @@ type Android struct { } type Notification struct { - Title string `json:"title"` - Body string `json:"body"` - ClickType string `json:"click_type"` + Title string `json:"title"` + Body string `json:"body"` + ChannelID string `json:"channelID"` + ChannelName string `json:"ChannelName"` + ClickType string `json:"click_type"` } type Options struct { @@ -135,9 +137,11 @@ func (g *Getui) Push(userIDList []string, alert, detailContent, operationID stri }{Alias: []string{userIDList[0]}}, } pushReq.PushMessage.Notification = Notification{ - Title: alert, - Body: alert, - ClickType: "startapp", + Title: alert, + Body: alert, + ClickType: "startapp", + ChannelID: config.Config.Push.Getui.ChannelID, + ChannelName: config.Config.Push.Getui.ChannelName, } pushReq.PushChannel.Ios.Aps.Sound = "default" pushReq.PushChannel.Ios.Aps.Alert = Alert{ diff --git a/pkg/common/config/config.go b/pkg/common/config/config.go index d5450aa11..6440467ba 100644 --- a/pkg/common/config/config.go +++ b/pkg/common/config/config.go @@ -199,6 +199,8 @@ type config struct { Enable bool `yaml:"enable"` Intent string `yaml:"intent"` MasterSecret string `yaml:"masterSecret"` + ChannelID string `yaml:"channelID"` + ChannelName string `yaml:"channelName"` } Fcm struct { ServiceAccount string `yaml:"serviceAccount"` From 1c53c90ab5c7da9bcca3ed0854222de96f0b87d4 Mon Sep 17 00:00:00 2001 From: wangchuxiao Date: Wed, 14 Sep 2022 10:29:49 +0800 Subject: [PATCH 3/3] hash --- pkg/common/db/rocks_cache/rocks_cache.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/common/db/rocks_cache/rocks_cache.go b/pkg/common/db/rocks_cache/rocks_cache.go index d698029b6..440ae40c5 100644 --- a/pkg/common/db/rocks_cache/rocks_cache.go +++ b/pkg/common/db/rocks_cache/rocks_cache.go @@ -394,6 +394,13 @@ func DelJoinedSuperGroupIDListFromCache(userID string) error { func GetGroupMemberListHashFromCache(groupID string) (uint64, error) { generateHash := func() (string, error) { + groupInfo, err := GetGroupInfoFromCache(groupID) + if err != nil { + return "0", utils.Wrap(err, "GetGroupInfoFromCache failed") + } + if groupInfo.Status == constant.GroupStatusDismissed { + return "0", nil + } groupMemberIDList, err := GetGroupMemberIDListFromCache(groupID) if err != nil { return "", utils.Wrap(err, "GetGroupMemberIDListFromCache failed") @@ -408,6 +415,9 @@ func GetGroupMemberListHashFromCache(groupID string) (uint64, error) { return strconv.Itoa(int(bi.Uint64())), nil } hashCode, err := db.DB.Rc.Fetch(groupMemberListHashCache+groupID, time.Second*30*60, generateHash) + if err != nil { + return 0, utils.Wrap(err, "fetch failed") + } hashCodeUint64, err := strconv.Atoi(hashCode) return uint64(hashCodeUint64), err }