mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-24 18:36:19 +08:00
exception handling
This commit is contained in:
parent
2b9a3536e7
commit
29f3fd46a8
@ -22,7 +22,6 @@ func key(dbAddress, dbName string) string {
|
|||||||
func init() {
|
func init() {
|
||||||
//mysql init
|
//mysql init
|
||||||
initMysqlDB()
|
initMysqlDB()
|
||||||
// mongo init
|
|
||||||
mgoDailInfo := &mgo.DialInfo{
|
mgoDailInfo := &mgo.DialInfo{
|
||||||
Addrs: config.Config.Mongo.DBAddress,
|
Addrs: config.Config.Mongo.DBAddress,
|
||||||
Direct: config.Config.Mongo.DBDirect,
|
Direct: config.Config.Mongo.DBDirect,
|
||||||
@ -40,6 +39,11 @@ func init() {
|
|||||||
DB.mgoSession = mgoSession
|
DB.mgoSession = mgoSession
|
||||||
DB.mgoSession.SetMode(mgo.Monotonic, true)
|
DB.mgoSession.SetMode(mgo.Monotonic, true)
|
||||||
|
|
||||||
|
c := DB.mgoSession.DB(config.Config.Mongo.DBDatabase).C(cChat)
|
||||||
|
err = c.EnsureIndexKey("uid")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
// redis pool init
|
// redis pool init
|
||||||
DB.redisPool = &redis.Pool{
|
DB.redisPool = &redis.Pool{
|
||||||
MaxIdle: config.Config.Redis.DBMaxIdle,
|
MaxIdle: config.Config.Redis.DBMaxIdle,
|
||||||
|
@ -22,6 +22,7 @@ type MsgInfo struct {
|
|||||||
type UserChat struct {
|
type UserChat struct {
|
||||||
UID string
|
UID string
|
||||||
Msg []MsgInfo
|
Msg []MsgInfo
|
||||||
|
BId bson.ObjectId `bson:"bid"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type GroupMember struct {
|
type GroupMember struct {
|
||||||
@ -155,12 +156,15 @@ func (d *DataBases) SaveUserChat(uid string, sendTime int64, m proto.Message) er
|
|||||||
|
|
||||||
log.NewInfo("", "get mgoSession cost time", getCurrentTimestampByMill()-newTime)
|
log.NewInfo("", "get mgoSession cost time", getCurrentTimestampByMill()-newTime)
|
||||||
c := session.DB(config.Config.Mongo.DBDatabase).C(cChat)
|
c := session.DB(config.Config.Mongo.DBDatabase).C(cChat)
|
||||||
|
err := c.EnsureIndexKey("uid")
|
||||||
|
if err != nil {
|
||||||
|
log.NewError("", "EnsureIndexKey uid failed ", err.Error())
|
||||||
|
}
|
||||||
n, err := c.Find(bson.M{"uid": uid}).Count()
|
n, err := c.Find(bson.M{"uid": uid}).Count()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.NewInfo("", "find mgo uid cost time", getCurrentTimestampByMill()-newTime)
|
log.NewInfo("", "find and create index mgo uid cost time", getCurrentTimestampByMill()-newTime)
|
||||||
sMsg := MsgInfo{}
|
sMsg := MsgInfo{}
|
||||||
sMsg.SendTime = sendTime
|
sMsg.SendTime = sendTime
|
||||||
if sMsg.Msg, err = proto.Marshal(m); err != nil {
|
if sMsg.Msg, err = proto.Marshal(m); err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user