mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-08-07 11:40:01 +08:00
fix delete
This commit is contained in:
parent
429bee7e6c
commit
5c5f80691a
@ -7,6 +7,7 @@ import (
|
|||||||
"Open_IM/pkg/common/log"
|
"Open_IM/pkg/common/log"
|
||||||
server_api_params "Open_IM/pkg/proto/sdk_ws"
|
server_api_params "Open_IM/pkg/proto/sdk_ws"
|
||||||
"Open_IM/pkg/utils"
|
"Open_IM/pkg/utils"
|
||||||
|
goRedis "github.com/go-redis/redis/v8"
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
"math"
|
"math"
|
||||||
)
|
)
|
||||||
@ -21,10 +22,13 @@ func ResetUserGroupMinSeq(operationID, groupID string, userIDList []string) erro
|
|||||||
log.NewError(operationID, utils.GetSelfFuncName(), groupID, "deleteMongoMsg failed")
|
log.NewError(operationID, utils.GetSelfFuncName(), groupID, "deleteMongoMsg failed")
|
||||||
return utils.Wrap(err, "")
|
return utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
|
if minSeq == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
log.NewDebug(operationID, utils.GetSelfFuncName(), "delMsgIDList:", delMsgIDList, "minSeq", minSeq)
|
log.NewDebug(operationID, utils.GetSelfFuncName(), "delMsgIDList:", delMsgIDList, "minSeq", minSeq)
|
||||||
for _, userID := range userIDList {
|
for _, userID := range userIDList {
|
||||||
userMinSeq, err := db.DB.GetGroupUserMinSeq(groupID, userID)
|
userMinSeq, err := db.DB.GetGroupUserMinSeq(groupID, userID)
|
||||||
if err != nil {
|
if err != nil && err != goRedis.Nil {
|
||||||
log.NewError(operationID, utils.GetSelfFuncName(), "GetGroupUserMinSeq failed", groupID, userID, err.Error())
|
log.NewError(operationID, utils.GetSelfFuncName(), "GetGroupUserMinSeq failed", groupID, userID, err.Error())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -46,6 +50,9 @@ func DeleteMongoMsgAndResetRedisSeq(operationID, userID string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return utils.Wrap(err, "")
|
return utils.Wrap(err, "")
|
||||||
}
|
}
|
||||||
|
if minSeq == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
log.NewDebug(operationID, utils.GetSelfFuncName(), "delMsgIDMap: ", delMsgIDList, "minSeq", minSeq)
|
log.NewDebug(operationID, utils.GetSelfFuncName(), "delMsgIDMap: ", delMsgIDList, "minSeq", minSeq)
|
||||||
err = db.DB.SetUserMinSeq(userID, minSeq)
|
err = db.DB.SetUserMinSeq(userID, minSeq)
|
||||||
return err
|
return err
|
||||||
@ -136,6 +143,9 @@ func checkMaxSeqWithMongo(operationID, ID string, diffusionType int) error {
|
|||||||
maxSeq, err = db.DB.GetGroupMaxSeq(ID)
|
maxSeq, err = db.DB.GetGroupMaxSeq(ID)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if err == goRedis.Nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return utils.Wrap(err, "GetUserMaxSeq failed")
|
return utils.Wrap(err, "GetUserMaxSeq failed")
|
||||||
}
|
}
|
||||||
msg, err := db.DB.GetNewestMsg(ID)
|
msg, err := db.DB.GetNewestMsg(ID)
|
||||||
|
@ -20,7 +20,7 @@ func StartCronTask() {
|
|||||||
fmt.Println("config", config.Config.Mongo.ChatRecordsClearTime)
|
fmt.Println("config", config.Config.Mongo.ChatRecordsClearTime)
|
||||||
_, err := c.AddFunc(config.Config.Mongo.ChatRecordsClearTime, func() {
|
_, err := c.AddFunc(config.Config.Mongo.ChatRecordsClearTime, func() {
|
||||||
operationID := getCronTaskOperationID()
|
operationID := getCronTaskOperationID()
|
||||||
log.NewInfo(operationID, "start", utils.GetSelfFuncName())
|
log.NewInfo(operationID, "====================== start del cron task ======================")
|
||||||
userIDList, err := im_mysql_model.SelectAllUserID()
|
userIDList, err := im_mysql_model.SelectAllUserID()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.NewDebug(operationID, utils.GetSelfFuncName(), "userIDList: ", userIDList)
|
log.NewDebug(operationID, utils.GetSelfFuncName(), "userIDList: ", userIDList)
|
||||||
@ -56,6 +56,8 @@ func StartCronTask() {
|
|||||||
log.NewError(operationID, utils.GetSelfFuncName(), err.Error())
|
log.NewError(operationID, utils.GetSelfFuncName(), err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.NewInfo(operationID, "====================== start del cron finished ======================")
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("start cron failed", err.Error())
|
fmt.Println("start cron failed", err.Error())
|
||||||
|
@ -263,13 +263,16 @@ func (d *DataBases) GetUserMsgListByIndex(ID string, index int64) (*UserChat, er
|
|||||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
|
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
|
||||||
regex := fmt.Sprintf("^%s", ID)
|
regex := fmt.Sprintf("^%s", ID)
|
||||||
findOpts := options.Find().SetLimit(1).SetSkip(index).SetSort(bson.M{"$regex": regex}).SetSort(bson.M{"uid": 1})
|
findOpts := options.Find().SetLimit(1).SetSkip(index).SetSort(bson.M{"uid": 1})
|
||||||
var msgs []UserChat
|
var msgs []UserChat
|
||||||
cursor, err := c.Find(ctx, bson.M{"uid": bson.M{"$regex": regex}}, findOpts)
|
cursor, err := c.Find(ctx, bson.M{"uid": bson.M{"$regex": regex}}, findOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = cursor.Decode(&msgs)
|
err = cursor.Decode(&msgs)
|
||||||
|
if err != nil {
|
||||||
|
return nil, utils.Wrap(err, "")
|
||||||
|
}
|
||||||
if len(msgs) > 0 {
|
if len(msgs) > 0 {
|
||||||
return &msgs[0], err
|
return &msgs[0], err
|
||||||
} else {
|
} else {
|
||||||
@ -306,13 +309,16 @@ func (d *DataBases) GetNewestMsg(ID string) (msg *MsgInfo, err error) {
|
|||||||
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
ctx, _ := context.WithTimeout(context.Background(), time.Duration(config.Config.Mongo.DBTimeout)*time.Second)
|
||||||
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
|
c := d.mongoClient.Database(config.Config.Mongo.DBDatabase).Collection(cChat)
|
||||||
regex := fmt.Sprintf("^%s", ID)
|
regex := fmt.Sprintf("^%s", ID)
|
||||||
findOpts := options.Find().SetLimit(1).SetSort(bson.M{"$regex": regex}).SetSort(bson.M{"uid": -1})
|
findOpts := options.Find().SetLimit(1).SetSort(bson.M{"uid": -1})
|
||||||
var userChats []UserChat
|
var userChats []UserChat
|
||||||
cursor, err := c.Find(ctx, bson.M{"uid": bson.M{"$regex": regex}}, findOpts)
|
cursor, err := c.Find(ctx, bson.M{"uid": bson.M{"$regex": regex}}, findOpts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
err = cursor.Decode(&userChats)
|
err = cursor.Decode(&userChats)
|
||||||
|
if err != nil {
|
||||||
|
return nil, utils.Wrap(err, "")
|
||||||
|
}
|
||||||
if len(userChats) > 0 {
|
if len(userChats) > 0 {
|
||||||
if len(userChats[0].Msg) > 0 {
|
if len(userChats[0].Msg) > 0 {
|
||||||
return &userChats[0].Msg[len(userChats[0].Msg)], nil
|
return &userChats[0].Msg[len(userChats[0].Msg)], nil
|
||||||
|
Loading…
x
Reference in New Issue
Block a user