Skip to content

Commit 2a6935e

Browse files
authored
Merge pull request #3667 from WhereAreBugs/3.8.3-patch
bugfix(conversation):removed unexpectedly called functions and itself…
2 parents 73ae47c + 203cdb5 commit 2a6935e

7 files changed

Lines changed: 23 additions & 97 deletions

File tree

internal/rpc/conversation/conversation.go

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
2525
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/cache/redis"
2626
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/database/mgo"
27-
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/model"
2827
dbModel "github.com/openimsdk/open-im-server/v3/pkg/common/storage/model"
2928
"github.com/openimsdk/open-im-server/v3/pkg/localcache"
3029
"github.com/openimsdk/open-im-server/v3/pkg/msgprocessor"
@@ -525,17 +524,6 @@ func (c *conversationServer) GetUserConversationIDsHash(ctx context.Context, req
525524
return &pbconversation.GetUserConversationIDsHashResp{Hash: hash}, nil
526525
}
527526

528-
func (c *conversationServer) GetConversationsByConversationID(
529-
ctx context.Context,
530-
req *pbconversation.GetConversationsByConversationIDReq,
531-
) (*pbconversation.GetConversationsByConversationIDResp, error) {
532-
conversations, err := c.conversationDatabase.GetConversationsByConversationID(ctx, req.ConversationIDs)
533-
if err != nil {
534-
return nil, err
535-
}
536-
return &pbconversation.GetConversationsByConversationIDResp{Conversations: convert.ConversationsDB2Pb(conversations)}, nil
537-
}
538-
539527
func (c *conversationServer) GetConversationOfflinePushUserIDs(ctx context.Context, req *pbconversation.GetConversationOfflinePushUserIDsReq) (*pbconversation.GetConversationOfflinePushUserIDsResp, error) {
540528
if req.ConversationID == "" {
541529
return nil, errs.ErrArgs.WrapMsg("conversationID is empty")
@@ -735,56 +723,6 @@ func (c *conversationServer) GetOwnerConversation(ctx context.Context, req *pbco
735723
}, nil
736724
}
737725

738-
func (c *conversationServer) GetConversationsNeedClearMsg(ctx context.Context, _ *pbconversation.GetConversationsNeedClearMsgReq) (*pbconversation.GetConversationsNeedClearMsgResp, error) {
739-
num, err := c.conversationDatabase.GetAllConversationIDsNumber(ctx)
740-
if err != nil {
741-
log.ZError(ctx, "GetAllConversationIDsNumber failed", err)
742-
return nil, err
743-
}
744-
const batchNum = 100
745-
746-
if num == 0 {
747-
return nil, errs.New("Need Destruct Msg is nil").Wrap()
748-
}
749-
750-
maxPage := (num + batchNum - 1) / batchNum
751-
752-
temp := make([]*model.Conversation, 0, maxPage*batchNum)
753-
754-
for pageNumber := 0; pageNumber < int(maxPage); pageNumber++ {
755-
pagination := &sdkws.RequestPagination{
756-
PageNumber: int32(pageNumber),
757-
ShowNumber: batchNum,
758-
}
759-
760-
conversationIDs, err := c.conversationDatabase.PageConversationIDs(ctx, pagination)
761-
if err != nil {
762-
log.ZError(ctx, "PageConversationIDs failed", err, "pageNumber", pageNumber)
763-
continue
764-
}
765-
766-
// log.ZDebug(ctx, "PageConversationIDs success", "pageNumber", pageNumber, "conversationIDsNum", len(conversationIDs), "conversationIDs", conversationIDs)
767-
if len(conversationIDs) == 0 {
768-
continue
769-
}
770-
771-
conversations, err := c.conversationDatabase.GetConversationsByConversationID(ctx, conversationIDs)
772-
if err != nil {
773-
log.ZError(ctx, "GetConversationsByConversationID failed", err, "conversationIDs", conversationIDs)
774-
continue
775-
}
776-
777-
for _, conversation := range conversations {
778-
if conversation.IsMsgDestruct && conversation.MsgDestructTime != 0 && ((time.Now().UnixMilli() > (conversation.MsgDestructTime + conversation.LatestMsgDestructTime.UnixMilli() + 8*60*60)) || // 8*60*60 is UTC+8
779-
conversation.LatestMsgDestructTime.IsZero()) {
780-
temp = append(temp, conversation)
781-
}
782-
}
783-
}
784-
785-
return &pbconversation.GetConversationsNeedClearMsgResp{Conversations: convert.ConversationsDB2Pb(temp)}, nil
786-
}
787-
788726
func (c *conversationServer) GetNotNotifyConversationIDs(ctx context.Context, req *pbconversation.GetNotNotifyConversationIDsReq) (*pbconversation.GetNotNotifyConversationIDsResp, error) {
789727
conversationIDs, err := c.conversationDatabase.GetNotNotifyConversationIDs(ctx, req.UserID)
790728
if err != nil {

internal/rpc/msg/delete.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import (
1919

2020
"github.com/openimsdk/open-im-server/v3/pkg/authverify"
2121
"github.com/openimsdk/protocol/constant"
22-
"github.com/openimsdk/protocol/conversation"
2322
"github.com/openimsdk/protocol/msg"
2423
"github.com/openimsdk/protocol/sdkws"
2524
"github.com/openimsdk/tools/log"
@@ -74,7 +73,7 @@ func (m *msgServer) DeleteMsgs(ctx context.Context, req *msg.DeleteMsgsReq) (*ms
7473
if err := m.MsgDatabase.DeleteMsgsPhysicalBySeqs(ctx, req.ConversationID, req.Seqs); err != nil {
7574
return nil, err
7675
}
77-
conv, err := m.conversationClient.GetConversationsByConversationID(ctx, req.ConversationID)
76+
conv, err := m.conversationClient.GetConversation(ctx, req.ConversationID, req.UserID)
7877
if err != nil {
7978
return nil, err
8079
}
@@ -113,14 +112,12 @@ func (m *msgServer) DeleteMsgPhysical(ctx context.Context, req *msg.DeleteMsgPhy
113112
}
114113

115114
func (m *msgServer) clearConversation(ctx context.Context, conversationIDs []string, userID string, deleteSyncOpt *msg.DeleteSyncOpt) error {
116-
conversations, err := m.conversationClient.GetConversationsByConversationIDs(ctx, conversationIDs)
115+
conversations, err := m.conversationClient.GetConversations(ctx, conversationIDs, userID)
117116
if err != nil {
118117
return err
119118
}
120-
var existConversations []*conversation.Conversation
121119
var existConversationIDs []string
122120
for _, conversation := range conversations {
123-
existConversations = append(existConversations, conversation)
124121
existConversationIDs = append(existConversationIDs, conversation.ConversationID)
125122
}
126123
log.ZDebug(ctx, "ClearConversationsMsg", "existConversationIDs", existConversationIDs)
@@ -149,7 +146,7 @@ func (m *msgServer) clearConversation(ctx context.Context, conversationIDs []str
149146
if err := m.MsgDatabase.SetMinSeqs(ctx, m.getMinSeqs(maxSeqs)); err != nil {
150147
return err
151148
}
152-
for _, conversation := range existConversations {
149+
for _, conversation := range conversations {
153150
tips := &sdkws.ClearConversationTips{UserID: userID, ConversationIDs: []string{conversation.ConversationID}}
154151
m.notificationSender.NotificationWithSessionType(ctx, userID, m.conversationAndGetRecvID(conversation, userID), constant.ClearConversationNotification, conversation.ConversationType, tips)
155152
}

pkg/common/storage/controller/conversation.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ type ConversationDatabase interface {
5959
GetAllConversationIDsNumber(ctx context.Context) (int64, error)
6060
// PageConversationIDs paginates through conversation IDs based on the specified pagination settings.
6161
PageConversationIDs(ctx context.Context, pagination pagination.Pagination) (conversationIDs []string, err error)
62-
// GetConversationsByConversationID retrieves conversations by their IDs.
63-
GetConversationsByConversationID(ctx context.Context, conversationIDs []string) ([]*relationtb.Conversation, error)
6462
// GetConversationIDsNeedDestruct fetches conversations that need to be destructed based on specific criteria.
6563
GetConversationIDsNeedDestruct(ctx context.Context) ([]*relationtb.Conversation, error)
6664
// GetConversationNotReceiveMessageUserIDs gets user IDs for users in a conversation who have not received messages.
@@ -348,10 +346,6 @@ func (c *conversationDatabase) PageConversationIDs(ctx context.Context, paginati
348346
return c.conversationDB.PageConversationIDs(ctx, pagination)
349347
}
350348

351-
func (c *conversationDatabase) GetConversationsByConversationID(ctx context.Context, conversationIDs []string) ([]*relationtb.Conversation, error) {
352-
return c.conversationDB.GetConversationsByConversationID(ctx, conversationIDs)
353-
}
354-
355349
func (c *conversationDatabase) GetConversationIDsNeedDestruct(ctx context.Context) ([]*relationtb.Conversation, error) {
356350
return c.conversationDB.GetConversationIDsNeedDestruct(ctx)
357351
}

pkg/common/storage/database/conversation.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ type Conversation interface {
3838
GetAllConversationIDs(ctx context.Context) ([]string, error)
3939
GetAllConversationIDsNumber(ctx context.Context) (int64, error)
4040
PageConversationIDs(ctx context.Context, pagination pagination.Pagination) (conversationIDs []string, err error)
41-
GetConversationsByConversationID(ctx context.Context, conversationIDs []string) ([]*model.Conversation, error)
4241
GetConversationIDsNeedDestruct(ctx context.Context) ([]*model.Conversation, error)
4342
GetConversationNotReceiveMessageUserIDs(ctx context.Context, conversationID string) ([]string, error)
4443
FindConversationUserVersion(ctx context.Context, userID string, version uint, limit int) (*model.VersionLog, error)

pkg/common/storage/database/mgo/conversation.go

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,25 @@ import (
3232

3333
func NewConversationMongo(db *mongo.Database) (*ConversationMgo, error) {
3434
coll := db.Collection(database.ConversationName)
35-
_, err := coll.Indexes().CreateOne(context.Background(), mongo.IndexModel{
36-
Keys: bson.D{
37-
{Key: "owner_user_id", Value: 1},
38-
{Key: "conversation_id", Value: 1},
35+
_, err := coll.Indexes().CreateMany(context.Background(), []mongo.IndexModel{
36+
{
37+
Keys: bson.D{
38+
{Key: "owner_user_id", Value: 1},
39+
{Key: "conversation_id", Value: 1},
40+
},
41+
Options: options.Index().SetUnique(true),
42+
},
43+
{
44+
Keys: bson.D{
45+
{Key: "user_id", Value: 1},
46+
},
47+
Options: options.Index(),
48+
},
49+
{
50+
Keys: bson.D{
51+
{Key: "conversation_id", Value: 1},
52+
},
3953
},
40-
Options: options.Index().SetUnique(true),
4154
})
4255
if err != nil {
4356
return nil, errs.Wrap(err)
@@ -191,10 +204,6 @@ func (c *ConversationMgo) PageConversationIDs(ctx context.Context, pagination pa
191204
return mongoutil.FindPageOnly[string](ctx, c.coll, bson.M{}, pagination, options.Find().SetProjection(bson.M{"conversation_id": 1}))
192205
}
193206

194-
func (c *ConversationMgo) GetConversationsByConversationID(ctx context.Context, conversationIDs []string) ([]*model.Conversation, error) {
195-
return mongoutil.Find[*model.Conversation](ctx, c.coll, bson.M{"conversation_id": bson.M{"$in": conversationIDs}})
196-
}
197-
198207
func (c *ConversationMgo) GetConversationIDsNeedDestruct(ctx context.Context) ([]*model.Conversation, error) {
199208
// "is_msg_destruct = 1 && msg_destruct_time != 0 && (UNIX_TIMESTAMP(NOW()) > (msg_destruct_time + UNIX_TIMESTAMP(latest_msg_destruct_time)) || latest_msg_destruct_time is NULL)"
200209
return mongoutil.Find[*model.Conversation](ctx, c.coll, bson.M{

pkg/rpcli/conversation.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package rpcli
22

33
import (
44
"context"
5+
56
"github.com/openimsdk/protocol/conversation"
67
"google.golang.org/grpc"
78
)
@@ -30,18 +31,6 @@ func (x *ConversationClient) SetConversations(ctx context.Context, ownerUserIDs
3031
return ignoreResp(x.ConversationClient.SetConversations(ctx, req))
3132
}
3233

33-
func (x *ConversationClient) GetConversationsByConversationIDs(ctx context.Context, conversationIDs []string) ([]*conversation.Conversation, error) {
34-
if len(conversationIDs) == 0 {
35-
return nil, nil
36-
}
37-
req := &conversation.GetConversationsByConversationIDReq{ConversationIDs: conversationIDs}
38-
return extractField(ctx, x.ConversationClient.GetConversationsByConversationID, req, (*conversation.GetConversationsByConversationIDResp).GetConversations)
39-
}
40-
41-
func (x *ConversationClient) GetConversationsByConversationID(ctx context.Context, conversationID string) (*conversation.Conversation, error) {
42-
return firstValue(x.GetConversationsByConversationIDs(ctx, []string{conversationID}))
43-
}
44-
4534
func (x *ConversationClient) SetConversationMinSeq(ctx context.Context, conversationID string, ownerUserIDs []string, minSeq int64) error {
4635
if len(ownerUserIDs) == 0 {
4736
return nil

start-config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ toolBinaries:
1515
- check-free-memory
1616
- check-component
1717
- seq
18-
maxFileDescriptors: 10000
18+
maxFileDescriptors: 100000

0 commit comments

Comments
 (0)