mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-04 09:05:59 +08:00
BatchInsertBlock
This commit is contained in:
@@ -146,7 +146,7 @@ func (db *commonMsgDatabase) BatchInsertBlock(ctx context.Context, conversationI
|
||||
return nil
|
||||
}
|
||||
num := db.msg.GetSingleGocMsgNum()
|
||||
num = 100
|
||||
//num = 100
|
||||
if msgList[0].Msg != nil {
|
||||
firstSeq = msgList[0].Msg.Seq
|
||||
}
|
||||
@@ -194,7 +194,7 @@ func (db *commonMsgDatabase) BatchInsertBlock(ctx context.Context, conversationI
|
||||
}
|
||||
doc := unRelationTb.MsgDocModel{
|
||||
DocID: docID,
|
||||
Msg: make([]unRelationTb.MsgInfoModel, num),
|
||||
Msg: make([]*unRelationTb.MsgInfoModel, num),
|
||||
}
|
||||
var insert int
|
||||
for j := i; j < len(msgList); j++ {
|
||||
@@ -203,14 +203,21 @@ func (db *commonMsgDatabase) BatchInsertBlock(ctx context.Context, conversationI
|
||||
break
|
||||
}
|
||||
insert++
|
||||
doc.Msg[getIndex(seq)] = *msgList[j]
|
||||
doc.Msg[getIndex(seq)] = msgList[j]
|
||||
}
|
||||
for i, model := range doc.Msg {
|
||||
if model.DelList == nil {
|
||||
doc.Msg[i].DelList = []string{}
|
||||
}
|
||||
if model.ReadList == nil {
|
||||
doc.Msg[i].ReadList = []string{}
|
||||
if model == nil {
|
||||
doc.Msg[i] = &unRelationTb.MsgInfoModel{
|
||||
DelList: []string{},
|
||||
ReadList: []string{},
|
||||
}
|
||||
} else {
|
||||
if model.DelList == nil {
|
||||
doc.Msg[i].DelList = []string{}
|
||||
}
|
||||
if model.ReadList == nil {
|
||||
doc.Msg[i].ReadList = []string{}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := db.msgDocDatabase.Create(ctx, &doc); err != nil {
|
||||
|
||||
@@ -197,3 +197,38 @@ func Test_Delete(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_Delete1(t *testing.T) {
|
||||
config.Config.Mongo.DBAddress = []string{"192.168.44.128:37017"}
|
||||
config.Config.Mongo.DBTimeout = 60
|
||||
config.Config.Mongo.DBDatabase = "openIM"
|
||||
config.Config.Mongo.DBSource = "admin"
|
||||
config.Config.Mongo.DBUserName = "root"
|
||||
config.Config.Mongo.DBPassword = "openIM123"
|
||||
config.Config.Mongo.DBMaxPoolSize = 100
|
||||
config.Config.Mongo.DBRetainChatRecords = 3650
|
||||
config.Config.Mongo.ChatRecordsClearTime = "0 2 * * 3"
|
||||
|
||||
mongo, err := unrelation.NewMongo()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = mongo.GetDatabase().Client().Ping(context.Background(), nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
c := mongo.GetClient().Database("openIM").Collection("msg")
|
||||
|
||||
var o unRelationTb.MsgDocModel
|
||||
|
||||
err = c.FindOne(context.Background(), bson.M{"doc_id": "test:0"}).Decode(&o)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for i, model := range o.Msg {
|
||||
fmt.Println(i, model == nil)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user