mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-07 18:45:58 +08:00
workMoments
This commit is contained in:
+60
-31
@@ -2,6 +2,8 @@ package db
|
||||
|
||||
import (
|
||||
"Open_IM/pkg/common/config"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
|
||||
//"Open_IM/pkg/common/log"
|
||||
"Open_IM/pkg/utils"
|
||||
"fmt"
|
||||
@@ -34,7 +36,6 @@ func key(dbAddress, dbName string) string {
|
||||
|
||||
func init() {
|
||||
//log.NewPrivateLog(constant.LogFileName)
|
||||
//var mgoSession *mgo.Session
|
||||
var mongoClient *mongo.Client
|
||||
var err1 error
|
||||
//mysql init
|
||||
@@ -66,39 +67,67 @@ func init() {
|
||||
}
|
||||
}
|
||||
fmt.Println("0", utils.GetSelfFuncName(), "mongo driver client init success: ", uri)
|
||||
// mongodb create index
|
||||
opts := options.CreateIndexes().SetMaxTime(10 * time.Second)
|
||||
dataBase := mongoClient.Database(config.Config.Mongo.DBDatabase)
|
||||
|
||||
cCommentMsgModels := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.M{"create_time": -1, "user_id": -1},
|
||||
},
|
||||
}
|
||||
result, err := dataBase.Collection(cCommentMsg).Indexes().CreateMany(context.Background(), cCommentMsgModels, opts)
|
||||
if err != nil {
|
||||
fmt.Println("mongodb create cCommentMsgModels failed", result, err.Error())
|
||||
}
|
||||
|
||||
cSendLogModels := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.M{"user_id": -1, "send_time": -1},
|
||||
},
|
||||
}
|
||||
result, err = dataBase.Collection(cSendLog).Indexes().CreateMany(context.Background(), cSendLogModels, opts)
|
||||
if err != nil {
|
||||
fmt.Println("mongodb create cSendLogModels failed", result, err.Error())
|
||||
}
|
||||
|
||||
cChatModels := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.M{"uid": -1},
|
||||
},
|
||||
}
|
||||
result, err = dataBase.Collection(cChat).Indexes().CreateMany(context.Background(), cChatModels, opts)
|
||||
if err != nil {
|
||||
fmt.Println("mongodb create cChatModels failed", result, err.Error())
|
||||
}
|
||||
|
||||
cWorkMomentModels := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.M{"work_moment_id": -1},
|
||||
},
|
||||
{
|
||||
Keys: bson.M{"user_id": -1, "create_time": -1},
|
||||
},
|
||||
}
|
||||
result, err = dataBase.Collection(cWorkMoment).Indexes().CreateMany(context.Background(), cWorkMomentModels, opts)
|
||||
if err != nil {
|
||||
fmt.Println("mongodb create cWorkMomentModels failed", result, err.Error())
|
||||
}
|
||||
|
||||
cTagModels := []mongo.IndexModel{
|
||||
{
|
||||
Keys: bson.M{"tag_id": -1},
|
||||
},
|
||||
{
|
||||
Keys: bson.M{"user_id": -1, "tag_id": -1},
|
||||
},
|
||||
}
|
||||
result, err = dataBase.Collection(cTag).Indexes().CreateMany(context.Background(), cTagModels, opts)
|
||||
if err != nil {
|
||||
fmt.Println("mongodb create cTagModels failed", result, err.Error())
|
||||
}
|
||||
DB.mongoClient = mongoClient
|
||||
|
||||
//mgoDailInfo := &mgo.DialInfo{
|
||||
// Addrs: config.Config.Mongo.DBAddress,
|
||||
// Direct: config.Config.Mongo.DBDirect,
|
||||
// Timeout: time.Second * time.Duration(config.Config.Mongo.DBTimeout),
|
||||
// Database: config.Config.Mongo.DBDatabase,
|
||||
// Source: config.Config.Mongo.DBSource,
|
||||
// Username: config.Config.Mongo.DBUserName,
|
||||
// Password: config.Config.Mongo.DBPassword,
|
||||
// PoolLimit: config.Config.Mongo.DBMaxPoolSize,
|
||||
//}
|
||||
//mgoSession, err = mgo.DialWithInfo(mgoDailInfo)
|
||||
//
|
||||
//if err != nil {
|
||||
//
|
||||
// mgoSession, err1 = mgo.DialWithInfo(mgoDailInfo)
|
||||
// if err1 != nil {
|
||||
// log.NewError(" mongo.Connect failed, panic", err.Error())
|
||||
// panic(err1.Error())
|
||||
// }
|
||||
//}
|
||||
|
||||
//DB.mgoSession = mgoSession
|
||||
//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.Error())
|
||||
//}
|
||||
//
|
||||
|
||||
// redis pool init
|
||||
DB.redisPool = &redis.Pool{
|
||||
MaxIdle: config.Config.Redis.DBMaxIdle,
|
||||
|
||||
Reference in New Issue
Block a user