mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-05 05:12:45 +08:00
* refactor: refactor workflows contents. * add tool workflows. * update field. * fix: remove chat error. * Fix err. * fix error. * remove cn comment. * update workflows files. * update infra config. * move workflows. * feat: update bot. * fix: solve uncorrect outdated msg get. * update get docIDs logic. * update * update skip logic. * fix * update. * fix: delay deleteObject func. * remove unused content. * update log type. * feat: implement request batch count limit. * update * update * feat: add rocksTimeout * feat: wrap logs * feat: add logs * feat: listen config * feat: enable listen TIME_WAIT port * feat: add logs * feat: cache batch * chore: enable fullUserCache * feat: push rpc num * feat: push err * feat: with operationID * feat: sleep * feat: change 1s * feat: change log * feat: implement Getbatch in rpcCache. * feat: print getOnline cost * feat: change log * feat: change kafka and push config * feat: del interface * feat: fix err * feat: change config * feat: go mod * feat: change config * feat: change config * feat: add sleep in push * feat: warn logs * feat: logs * feat: logs * feat: change port * feat: start config * feat: remove port reuse * feat: prometheus config * feat: prometheus config * feat: prometheus config * feat: add long time send msg to grafana * feat: init * feat: init * feat: implement offline push. * feat: batch get user online * feat: implement batch Push spilt * update go mod * Revert "feat: change port" This reverts commit 06d5e944 * feat: change port * feat: change config * feat: implement kafka producer and consumer. * update format, * add PushMQ log. * feat: get all online users and init push * feat: lock in online cache * feat: config * fix: init online status * fix: add logs * fix: userIDs * fix: add logs * feat: update Handler logic. * update MQ logic. * update * update * fix: method name * fix: update OfflinePushConsumerHandler. * fix: prommetrics * fix: add logs * fix: ctx * fix: log * fix: config * feat: change port * fix: atomic online cache status --------- Co-authored-by: Monet Lee <monet_lee@163.com>
126 lines
3.9 KiB
Go
126 lines
3.9 KiB
Go
package msg
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
|
|
"github.com/openimsdk/open-im-server/v3/pkg/common/convert"
|
|
pbconversation "github.com/openimsdk/protocol/conversation"
|
|
"github.com/openimsdk/protocol/msg"
|
|
"github.com/openimsdk/protocol/wrapperspb"
|
|
"github.com/openimsdk/tools/errs"
|
|
"github.com/openimsdk/tools/log"
|
|
"github.com/openimsdk/tools/mcontext"
|
|
"github.com/openimsdk/tools/utils/idutil"
|
|
"github.com/openimsdk/tools/utils/stringutil"
|
|
"golang.org/x/sync/errgroup"
|
|
)
|
|
|
|
// hard delete in Database.
|
|
func (m *msgServer) ClearMsg(ctx context.Context, req *msg.ClearMsgReq) (_ *msg.ClearMsgResp, err error) {
|
|
if err := authverify.CheckAdmin(ctx, m.config.Share.IMAdminUserID); err != nil {
|
|
return nil, err
|
|
}
|
|
if req.Timestamp > time.Now().UnixMilli() {
|
|
return nil, errs.ErrArgs.WrapMsg("request millisecond timestamp error")
|
|
}
|
|
var (
|
|
docNum int
|
|
msgNum int
|
|
start = time.Now()
|
|
)
|
|
|
|
clearMsg := func(ctx context.Context) (bool, error) {
|
|
docIDs, err := m.MsgDatabase.GetDocIDs(ctx)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
msgs, err := m.MsgDatabase.GetBeforeMsg(ctx, req.Timestamp, docIDs, 5000)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
if len(msgs) == 0 {
|
|
return false, nil
|
|
}
|
|
|
|
for _, msg := range msgs {
|
|
index, err := m.MsgDatabase.DeleteDocMsgBefore(ctx, req.Timestamp, msg)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
if len(index) == 0 {
|
|
return false, errs.ErrInternalServer.WrapMsg("delete doc msg failed")
|
|
}
|
|
|
|
docNum++
|
|
msgNum += len(index)
|
|
}
|
|
|
|
return true, nil
|
|
}
|
|
|
|
_, err = clearMsg(ctx)
|
|
if err != nil {
|
|
log.ZError(ctx, "clear msg failed", err, "docNum", docNum, "msgNum", msgNum, "cost", time.Since(start))
|
|
return nil, err
|
|
}
|
|
|
|
log.ZDebug(ctx, "clearing message", "docNum", docNum, "msgNum", msgNum, "cost", time.Since(start))
|
|
|
|
return &msg.ClearMsgResp{}, nil
|
|
}
|
|
|
|
// soft delete for self
|
|
func (m *msgServer) DestructMsgs(ctx context.Context, req *msg.DestructMsgsReq) (_ *msg.DestructMsgsResp, err error) {
|
|
temp := convert.ConversationsPb2DB(req.Conversations)
|
|
|
|
batchNum := 100
|
|
|
|
errg, _ := errgroup.WithContext(ctx)
|
|
errg.SetLimit(100)
|
|
|
|
for i := 0; i < len(temp); i += batchNum {
|
|
batch := temp[i:min(i+batchNum, len(temp))]
|
|
|
|
errg.Go(func() error {
|
|
for _, conversation := range batch {
|
|
handleCtx := mcontext.NewCtx(stringutil.GetSelfFuncName() + "-" + idutil.OperationIDGenerator() + "-" + conversation.ConversationID + "-" + conversation.OwnerUserID)
|
|
log.ZDebug(handleCtx, "User MsgsDestruct",
|
|
"conversationID", conversation.ConversationID,
|
|
"ownerUserID", conversation.OwnerUserID,
|
|
"msgDestructTime", conversation.MsgDestructTime,
|
|
"lastMsgDestructTime", conversation.LatestMsgDestructTime)
|
|
|
|
seqs, err := m.MsgDatabase.UserMsgsDestruct(handleCtx, conversation.OwnerUserID, conversation.ConversationID, conversation.MsgDestructTime, conversation.LatestMsgDestructTime)
|
|
if err != nil {
|
|
log.ZError(handleCtx, "user msg destruct failed", err, "conversationID", conversation.ConversationID, "ownerUserID", conversation.OwnerUserID)
|
|
continue
|
|
}
|
|
|
|
if len(seqs) > 0 {
|
|
if err := m.Conversation.UpdateConversation(handleCtx,
|
|
&pbconversation.UpdateConversationReq{
|
|
UserIDs: []string{conversation.OwnerUserID},
|
|
ConversationID: conversation.ConversationID,
|
|
LatestMsgDestructTime: wrapperspb.Int64(time.Now().UnixMilli())}); err != nil {
|
|
log.ZError(handleCtx, "updateUsersConversationField failed", err, "conversationID", conversation.ConversationID, "ownerUserID", conversation.OwnerUserID)
|
|
continue
|
|
}
|
|
|
|
// if you need Notify SDK client userseq is update.
|
|
// m.msgNotificationSender.UserDeleteMsgsNotification(handleCtx, conversation.OwnerUserID, conversation.ConversationID, seqs)
|
|
}
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
|
|
if err := errg.Wait(); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return nil, nil
|
|
}
|