-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: GroupApplicationAcceptedNotification * fix: GroupApplicationAcceptedNotification * fix: NotificationUserInfoUpdate * cicd: robot automated Change * fix: component * fix: getConversationInfo * feat: cron task * feat: cron task * feat: cron task * feat: cron task * feat: cron task --------- Co-authored-by: withchao <[email protected]>
- Loading branch information
Showing
20 changed files
with
355 additions
and
648 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
chatRecordsClearTime: "0 2 * * 3" | ||
msgDestructTime: "0 2 * * *" | ||
chatRecordsClearTime: "0 2 * * *" | ||
retainChatRecords: 365 | ||
enableCronLocker: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package msg | ||
|
||
import ( | ||
"context" | ||
"github.com/openimsdk/open-im-server/v3/pkg/authverify" | ||
"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" | ||
"strings" | ||
"time" | ||
) | ||
|
||
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) { | ||
conversationSeqs := make(map[string]struct{}) | ||
defer func() { | ||
req := &conversation.UpdateConversationReq{ | ||
MsgDestructTime: wrapperspb.Int64(time.Now().UnixMilli()), | ||
} | ||
for conversationID := range conversationSeqs { | ||
req.ConversationID = conversationID | ||
if err := m.Conversation.UpdateConversations(ctx, req); err != nil { | ||
log.ZError(ctx, "update conversation max seq failed", err, "conversationID", conversationID, "msgDestructTime", req.MsgDestructTime) | ||
} | ||
} | ||
}() | ||
msgs, err := m.MsgDatabase.GetBeforeMsg(ctx, req.Timestamp, 100) | ||
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) | ||
conversationID := msg.DocID[:strings.LastIndex(msg.DocID, ":")] | ||
if _, ok := conversationSeqs[conversationID]; !ok { | ||
conversationSeqs[conversationID] = struct{}{} | ||
} | ||
} | ||
return true, nil | ||
} | ||
for { | ||
keep, err := clearMsg(ctx) | ||
if err != nil { | ||
log.ZError(ctx, "clear msg failed", err, "docNum", docNum, "msgNum", msgNum, "cost", time.Since(start)) | ||
return nil, err | ||
} | ||
if !keep { | ||
log.ZInfo(ctx, "clear msg success", "docNum", docNum, "msgNum", msgNum, "cost", time.Since(start)) | ||
break | ||
} | ||
log.ZInfo(ctx, "clearing message", "docNum", docNum, "msgNum", msgNum, "cost", time.Since(start)) | ||
} | ||
return &msg.ClearMsgResp{}, nil | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.