commit
f8a649e7cc
@ -0,0 +1,32 @@
|
|||||||
|
package tools
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/OpenIMSDK/Open-IM-Server/pkg/msgprocessor"
|
||||||
|
"github.com/OpenIMSDK/protocol/constant"
|
||||||
|
"github.com/OpenIMSDK/tools/log"
|
||||||
|
"github.com/OpenIMSDK/tools/mcontext"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (c *MsgTool) ConvertTools() {
|
||||||
|
ctx := mcontext.NewCtx("convert")
|
||||||
|
conversationIDs, err := c.conversationDatabase.GetAllConversationIDs(ctx)
|
||||||
|
if err != nil {
|
||||||
|
log.ZError(ctx, "get all conversation ids failed", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, conversationID := range conversationIDs {
|
||||||
|
conversationIDs = append(conversationIDs, msgprocessor.GetNotificationConversationIDByConversationID(conversationID))
|
||||||
|
}
|
||||||
|
userIDs, err := c.userDatabase.GetAllUserID(ctx, 0, 0)
|
||||||
|
if err != nil {
|
||||||
|
log.ZError(ctx, "get all user ids failed", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.ZDebug(ctx, "all userIDs", "len userIDs", len(userIDs))
|
||||||
|
for _, userID := range userIDs {
|
||||||
|
conversationIDs = append(conversationIDs, msgprocessor.GetConversationIDBySessionType(constant.SingleChatType, userID, userID))
|
||||||
|
conversationIDs = append(conversationIDs, msgprocessor.GetNotificationConversationID(constant.SingleChatType, userID, userID))
|
||||||
|
}
|
||||||
|
log.ZDebug(ctx, "all conversationIDs", "len userIDs", len(conversationIDs))
|
||||||
|
c.msgDatabase.ConvertMsgsDocLen(ctx, conversationIDs)
|
||||||
|
}
|
@ -0,0 +1,67 @@
|
|||||||
|
package unrelation
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
table "github.com/OpenIMSDK/Open-IM-Server/pkg/common/db/table/unrelation"
|
||||||
|
"github.com/OpenIMSDK/tools/log"
|
||||||
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (m *MsgMongoDriver) ConvertMsgsDocLen(ctx context.Context, conversationIDs []string) {
|
||||||
|
for _, conversationID := range conversationIDs {
|
||||||
|
regex := primitive.Regex{Pattern: fmt.Sprintf("^%s:", conversationID)}
|
||||||
|
cursor, err := m.MsgCollection.Find(ctx, bson.M{"doc_id": regex})
|
||||||
|
if err != nil {
|
||||||
|
log.ZError(ctx, "convertAll find msg doc failed", err, "conversationID", conversationID)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var msgDocs []table.MsgDocModel
|
||||||
|
err = cursor.All(ctx, &msgDocs)
|
||||||
|
if err != nil {
|
||||||
|
log.ZError(ctx, "convertAll cursor all failed", err, "conversationID", conversationID)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if len(msgDocs) < 1 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
log.ZInfo(ctx, "msg doc convert", "conversationID", conversationID, "len(msgDocs)", len(msgDocs))
|
||||||
|
if len(msgDocs[0].Msg) == int(m.model.GetSingleGocMsgNum5000()) {
|
||||||
|
if _, err := m.MsgCollection.DeleteMany(ctx, bson.M{"doc_id": regex}); err != nil {
|
||||||
|
log.ZError(ctx, "convertAll delete many failed", err, "conversationID", conversationID)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var newMsgDocs []interface{}
|
||||||
|
for _, msgDoc := range msgDocs {
|
||||||
|
if int64(len(msgDoc.Msg)) == m.model.GetSingleGocMsgNum() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var index int64
|
||||||
|
for index < int64(len(msgDoc.Msg)) {
|
||||||
|
msg := msgDoc.Msg[index]
|
||||||
|
if msg != nil && msg.Msg != nil {
|
||||||
|
msgDocModel := table.MsgDocModel{DocID: m.model.GetDocID(conversationID, msg.Msg.Seq)}
|
||||||
|
end := index + m.model.GetSingleGocMsgNum()
|
||||||
|
if int(end) >= len(msgDoc.Msg) {
|
||||||
|
msgDocModel.Msg = msgDoc.Msg[index:]
|
||||||
|
} else {
|
||||||
|
msgDocModel.Msg = msgDoc.Msg[index:end]
|
||||||
|
}
|
||||||
|
newMsgDocs = append(newMsgDocs, msgDocModel)
|
||||||
|
index = end
|
||||||
|
} else {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_, err = m.MsgCollection.InsertMany(ctx, newMsgDocs)
|
||||||
|
if err != nil {
|
||||||
|
log.ZError(ctx, "convertAll insert many failed", err, "conversationID", conversationID, "len(newMsgDocs)", len(newMsgDocs))
|
||||||
|
} else {
|
||||||
|
log.ZInfo(ctx, "msg doc convert", "conversationID", conversationID, "len(newMsgDocs)", len(newMsgDocs))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
cd %~p0../_output/bin/platforms/windows
|
||||||
|
start api.exe -p 10002
|
||||||
|
start auth.exe -p 10060
|
||||||
|
start conversation.exe -p 10080
|
||||||
|
start friend.exe -p 10020
|
||||||
|
start group.exe -p 10050
|
||||||
|
start msg.exe -p 10030
|
||||||
|
start msggateway.exe -p 10040 -w 10001
|
||||||
|
start msgtransfer.exe
|
||||||
|
start third.exe -p 10090
|
||||||
|
start push.exe -p 10070
|
||||||
|
start user.exe -p 10010
|
Loading…
Reference in new issue