mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-06 04:15:46 +08:00
BatchInsertBlock
This commit is contained in:
parent
2401cd3525
commit
1ba6bef27a
@ -275,6 +275,9 @@ func (db *commonMsgDatabase) BatchInsertBlock(ctx context.Context, conversationI
|
||||
}
|
||||
|
||||
func (db *commonMsgDatabase) BatchInsertChat2DB(ctx context.Context, conversationID string, msgList []*sdkws.MsgData, currentMaxSeq int64) error {
|
||||
if len(msgList) == 0 {
|
||||
return errs.ErrArgs.Wrap("msgList is empty")
|
||||
}
|
||||
msgs := make([]any, len(msgList))
|
||||
for i, msg := range msgList {
|
||||
if msg == nil {
|
||||
@ -314,7 +317,18 @@ func (db *commonMsgDatabase) BatchInsertChat2DB(ctx context.Context, conversatio
|
||||
Ex: msg.Ex,
|
||||
}
|
||||
}
|
||||
return db.BatchInsertBlock(ctx, conversationID, msgs, updateKeyMsg, currentMaxSeq-int64(len(msgList)))
|
||||
return db.BatchInsertBlock(ctx, conversationID, msgs, updateKeyMsg, msgList[0].Seq)
|
||||
}
|
||||
|
||||
func (db *commonMsgDatabase) MarkUserDeleteMsg(ctx context.Context, conversationID string, seq int64, userIDs []string) error {
|
||||
if len(userIDs) == 0 {
|
||||
return nil
|
||||
}
|
||||
msgs := make([]any, len(userIDs))
|
||||
for i, userID := range userIDs {
|
||||
msgs[i] = userID
|
||||
}
|
||||
return db.BatchInsertBlock(ctx, conversationID, msgs, updateKeyDel, seq)
|
||||
}
|
||||
|
||||
func (db *commonMsgDatabase) RevokeMsg(ctx context.Context, conversationID string, seq int64, revoke *unRelationTb.RevokeModel) error {
|
||||
|
@ -152,16 +152,14 @@ func GetDB() *commonMsgDatabase {
|
||||
func Test_Insert(t *testing.T) {
|
||||
db := GetDB()
|
||||
ctx := context.Background()
|
||||
var arr []*unRelationTb.MsgInfoModel
|
||||
var arr []any
|
||||
for i := 0; i < 345; i++ {
|
||||
arr = append(arr, &unRelationTb.MsgInfoModel{
|
||||
Msg: &unRelationTb.MsgDataModel{
|
||||
Seq: int64(i),
|
||||
Content: fmt.Sprintf("test-%d", i),
|
||||
},
|
||||
arr = append(arr, &unRelationTb.MsgDataModel{
|
||||
Seq: int64(i),
|
||||
Content: fmt.Sprintf("test-%d", i),
|
||||
})
|
||||
}
|
||||
if err := db.BatchInsertBlock(ctx, "test", arr, 0); err != nil {
|
||||
if err := db.BatchInsertBlock(ctx, "test", arr, updateKeyMsg, 0); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@ -169,17 +167,15 @@ func Test_Insert(t *testing.T) {
|
||||
func Test_Revoke(t *testing.T) {
|
||||
db := GetDB()
|
||||
ctx := context.Background()
|
||||
var arr []*unRelationTb.MsgInfoModel
|
||||
var arr []any
|
||||
for i := 0; i < 456; i++ {
|
||||
arr = append(arr, &unRelationTb.MsgInfoModel{
|
||||
Revoke: &unRelationTb.RevokeModel{
|
||||
UserID: "uid_" + strconv.Itoa(i),
|
||||
Nickname: "uname_" + strconv.Itoa(i),
|
||||
Time: time.Now().UnixMilli(),
|
||||
},
|
||||
arr = append(arr, &unRelationTb.RevokeModel{
|
||||
UserID: "uid_" + strconv.Itoa(i),
|
||||
Nickname: "uname_" + strconv.Itoa(i),
|
||||
Time: time.Now().UnixMilli(),
|
||||
})
|
||||
}
|
||||
if err := db.BatchInsertBlock(ctx, "test", arr, 123); err != nil {
|
||||
if err := db.BatchInsertBlock(ctx, "test", arr, updateKeyRevoke, 123); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
@ -187,48 +183,46 @@ func Test_Revoke(t *testing.T) {
|
||||
func Test_Delete(t *testing.T) {
|
||||
db := GetDB()
|
||||
ctx := context.Background()
|
||||
var arr []*unRelationTb.MsgInfoModel
|
||||
var arr []any
|
||||
for i := 0; i < 123; i++ {
|
||||
arr = append(arr, &unRelationTb.MsgInfoModel{
|
||||
DelList: []string{"uid_1", "uid_2"},
|
||||
})
|
||||
arr = append(arr, []string{"uid_1", "uid_2"})
|
||||
}
|
||||
if err := db.BatchInsertBlock(ctx, "test", arr, 210); err != nil {
|
||||
if err := db.BatchInsertBlock(ctx, "test", arr, updateKeyDel, 210); err != nil {
|
||||
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)
|
||||
}
|
||||
|
||||
}
|
||||
//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)
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
Loading…
x
Reference in New Issue
Block a user