Skip to content

Commit 123abe9

Browse files
authored
fix: fill in the most recent sendTime for a gap message to prevent the client from repeatedly retrieving the same message due to sendTime being 0. (#3522)
1 parent 34971c8 commit 123abe9

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import (
55
"fmt"
66
"time"
77

8+
"go.mongodb.org/mongo-driver/bson"
9+
"go.mongodb.org/mongo-driver/bson/primitive"
10+
"go.mongodb.org/mongo-driver/mongo"
11+
"go.mongodb.org/mongo-driver/mongo/options"
12+
813
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/database"
914
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/model"
1015
"github.com/openimsdk/protocol/constant"
@@ -14,10 +19,6 @@ import (
1419
"github.com/openimsdk/tools/errs"
1520
"github.com/openimsdk/tools/utils/datautil"
1621
"github.com/openimsdk/tools/utils/jsonutil"
17-
"go.mongodb.org/mongo-driver/bson"
18-
"go.mongodb.org/mongo-driver/bson/primitive"
19-
"go.mongodb.org/mongo-driver/mongo"
20-
"go.mongodb.org/mongo-driver/mongo/options"
2122
)
2223

2324
func NewMsgMongo(db *mongo.Database) (database.Msg, error) {
@@ -1154,7 +1155,7 @@ func (m *MsgMgo) findBeforeDocSendTime(ctx context.Context, docID string, limit
11541155
if err != nil {
11551156
return 0, 0, err
11561157
}
1157-
for i := len(res) - 1; i > 0; i-- {
1158+
for i := len(res) - 1; i >= 0; i-- {
11581159
v := res[i]
11591160
if v.Msgs != nil && v.Msgs.Msg != nil && v.Msgs.Msg.SendTime > 0 {
11601161
return v.Msgs.Msg.Seq, v.Msgs.Msg.SendTime, nil
@@ -1169,7 +1170,7 @@ func (m *MsgMgo) findBeforeSendTime(ctx context.Context, conversationID string,
11691170
limit := int64(-1)
11701171
if first {
11711172
first = false
1172-
limit = m.model.GetMsgIndex(seq)
1173+
limit = m.model.GetLimitForSingleDoc(seq)
11731174
}
11741175
docID := m.model.BuildDocIDByIndex(conversationID, i)
11751176
msgSeq, msgSendTime, err := m.findBeforeDocSendTime(ctx, docID, limit)

pkg/common/storage/model/msg.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ func (*MsgDocModel) GetMsgIndex(seq int64) int64 {
132132
return (seq - 1) % singleGocMsgNum
133133
}
134134

135+
func (*MsgDocModel) GetLimitForSingleDoc(seq int64) int64 {
136+
return seq % singleGocMsgNum
137+
}
138+
135139
func (*MsgDocModel) indexGen(conversationID string, seqSuffix int64) string {
136140
return conversationID + ":" + strconv.FormatInt(seqSuffix, 10)
137141
}

0 commit comments

Comments
 (0)