bug fix and shell optimization

This commit is contained in:
Gordon
2021-09-13 15:48:19 +08:00
parent c1bcadd9ed
commit 649bc5657e
14 changed files with 72 additions and 42 deletions
+4
View File
@@ -2,6 +2,7 @@ package db
import (
"Open_IM/src/common/config"
"Open_IM/src/common/log"
"fmt"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mysql"
@@ -15,10 +16,13 @@ type mysqlDB struct {
}
func initMysqlDB() {
//When there is no open IM database, connect to the mysql built-in database to create openIM database
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], "mysql")
db, err := gorm.Open("mysql", dsn)
if err != nil {
log.Error("", "", dsn)
panic(err)
}
@@ -37,7 +37,7 @@ func InsertMessageToChatLog(msgData pbMsg.WSToMsgSvrChatMsg) error {
MsgId: msgData.MsgID,
SendID: msgData.SendID,
RecvID: msgData.RecvID,
SendTime: utils.UnixSecondToTime(msgData.SendTime),
SendTime: utils.UnixNanoSecondToTime(msgData.SendTime),
SessionType: msgData.SessionType,
ContentType: msgData.ContentType,
MsgFrom: msgData.MsgFrom,
+1 -1
View File
@@ -59,7 +59,7 @@ func (ws *WServer) readMsg(conn *websocket.Conn) {
for {
msgType, msg, err := conn.ReadMessage()
if err != nil {
log.ErrorByKv("WS ReadMsg error", "", "userIP", conn.RemoteAddr().String(), "userUid", ws.getUserUid(conn), "error", err, "conn", conn)
log.ErrorByKv("WS ReadMsg error", "", "userIP", conn.RemoteAddr().String(), "userUid", ws.getUserUid(conn), "error", err)
ws.delUserConn(conn)
return
} else {
@@ -109,6 +109,7 @@ func (mc *HistoryConsumerHandler) ConsumeClaim(sess sarama.ConsumerGroupSession,
for msg := range claim.Messages() {
log.InfoByKv("kafka get info to mongo", "", "msgTopic", msg.Topic, "msgPartition", msg.Partition, "chat", string(msg.Value))
mc.msgHandle[msg.Topic](msg.Value, string(msg.Key))
sess.MarkMessage(msg, "")
}
return nil
}
@@ -69,6 +69,7 @@ func (pc *PersistentConsumerHandler) ConsumeClaim(sess sarama.ConsumerGroupSessi
for msg := range claim.Messages() {
log.InfoByKv("kafka get info to mysql", "", "msgTopic", msg.Topic, "msgPartition", msg.Partition, "chat", string(msg.Value))
pc.msgHandle[msg.Topic](msg.Value, string(msg.Key))
sess.MarkMessage(msg, "")
}
return nil
}
+7 -2
View File
@@ -2,6 +2,7 @@ package rpcChat
import (
"context"
"github.com/garyburd/redigo/redis"
commonDB "Open_IM/src/common/db"
"Open_IM/src/common/log"
@@ -23,8 +24,12 @@ func (rpc *rpcChat) GetNewSeq(_ context.Context, in *pbMsg.GetNewSeqReq) (*pbMsg
resp.ErrMsg = ""
return resp, err
} else {
log.ErrorByKv("getSeq from redis error", in.OperationID, "args", in.String(), "err", err.Error())
resp.Seq = 0
if err == redis.ErrNil {
resp.Seq = 0
} else {
log.ErrorByKv("getSeq from redis error", in.OperationID, "args", in.String(), "err", err.Error())
resp.Seq = -1
}
resp.ErrCode = 0
resp.ErrMsg = ""
return resp, nil
@@ -13,7 +13,7 @@ func (s *groupServer) GetGroupApplicationList(_ context.Context, pb *group.GetGr
reply, err := im_mysql_model.GetGroupApplicationList(pb.UID)
if err != nil {
log.Error("", "", "rpc GetGroupApplicationList call..., im_mysql_model.GetGroupApplicationList fail [uid: %s] [err: %s]", pb.UID, err.Error())
return nil, err
return &group.GetGroupApplicationListResp{ErrCode: 701, ErrMsg: "GetGroupApplicationList failed"}, nil
}
log.Info("", "", "rpc GetGroupApplicationList call..., im_mysql_model.GetGroupApplicationList")
@@ -14,7 +14,7 @@ func (s *groupServer) GroupApplicationResponse(_ context.Context, pb *group.Grou
reply, err := im_mysql_model.GroupApplicationResponse(pb)
if err != nil {
log.Error("", "", "rpc GroupApplicationResponse call..., im_mysql_model.GroupApplicationResponse fail [pb: %s] [err: %s]", pb.String(), err.Error())
return nil, err
return &group.GroupApplicationResponseResp{ErrCode: 702, ErrMsg: "rpc GroupApplicationResponse failed"}, nil
}
if pb.HandleResult == 1 {
+20 -9
View File
@@ -41,18 +41,29 @@ func (s *userServer) UpdateUserInfo(ctx context.Context, req *pbUser.UpdateUserI
}
if RpcResp.ErrorCode != 0 {
log.ErrorByKv("get friend list rpc server failed", req.OperationID, "err", err.Error(), "req", req.String())
}
self, err := im_mysql_model.FindUserByUID(claims.UID)
if err != nil {
log.ErrorByKv("get self info failed", req.OperationID, "err", err.Error(), "req", req.String())
}
var name, faceUrl string
if self != nil {
name, faceUrl = self.Name, self.Icon
}
for _, v := range RpcResp.Data {
logic.SendMsgByWS(&pbChat.WSToMsgSvrChatMsg{
SendID: claims.UID,
RecvID: v.Uid,
Content: claims.UID + "'s info has changed",
SendTime: utils.GetCurrentTimestampBySecond(),
MsgFrom: constant.SysMsgType,
ContentType: constant.SetSelfInfoTip,
SessionType: constant.SingleChatType,
OperationID: req.OperationID,
Token: req.Token,
SendID: claims.UID,
RecvID: v.Uid,
SenderNickName: name,
SenderFaceURL: faceUrl,
Content: claims.UID + "'s info has changed",
SendTime: utils.GetCurrentTimestampBySecond(),
MsgFrom: constant.SysMsgType,
ContentType: constant.SetSelfInfoTip,
SessionType: constant.SingleChatType,
OperationID: req.OperationID,
Token: req.Token,
})
}