mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-08-15 16:36:28 +08:00
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)
This commit is contained in:
parent
34971c8b96
commit
123abe9803
@ -5,6 +5,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"go.mongodb.org/mongo-driver/bson"
|
||||||
|
"go.mongodb.org/mongo-driver/bson/primitive"
|
||||||
|
"go.mongodb.org/mongo-driver/mongo"
|
||||||
|
"go.mongodb.org/mongo-driver/mongo/options"
|
||||||
|
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/database"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/database"
|
||||||
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/model"
|
"github.com/openimsdk/open-im-server/v3/pkg/common/storage/model"
|
||||||
"github.com/openimsdk/protocol/constant"
|
"github.com/openimsdk/protocol/constant"
|
||||||
@ -14,10 +19,6 @@ import (
|
|||||||
"github.com/openimsdk/tools/errs"
|
"github.com/openimsdk/tools/errs"
|
||||||
"github.com/openimsdk/tools/utils/datautil"
|
"github.com/openimsdk/tools/utils/datautil"
|
||||||
"github.com/openimsdk/tools/utils/jsonutil"
|
"github.com/openimsdk/tools/utils/jsonutil"
|
||||||
"go.mongodb.org/mongo-driver/bson"
|
|
||||||
"go.mongodb.org/mongo-driver/bson/primitive"
|
|
||||||
"go.mongodb.org/mongo-driver/mongo"
|
|
||||||
"go.mongodb.org/mongo-driver/mongo/options"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewMsgMongo(db *mongo.Database) (database.Msg, error) {
|
func NewMsgMongo(db *mongo.Database) (database.Msg, error) {
|
||||||
@ -1154,7 +1155,7 @@ func (m *MsgMgo) findBeforeDocSendTime(ctx context.Context, docID string, limit
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, 0, err
|
return 0, 0, err
|
||||||
}
|
}
|
||||||
for i := len(res) - 1; i > 0; i-- {
|
for i := len(res) - 1; i >= 0; i-- {
|
||||||
v := res[i]
|
v := res[i]
|
||||||
if v.Msgs != nil && v.Msgs.Msg != nil && v.Msgs.Msg.SendTime > 0 {
|
if v.Msgs != nil && v.Msgs.Msg != nil && v.Msgs.Msg.SendTime > 0 {
|
||||||
return v.Msgs.Msg.Seq, v.Msgs.Msg.SendTime, nil
|
return v.Msgs.Msg.Seq, v.Msgs.Msg.SendTime, nil
|
||||||
@ -1169,7 +1170,7 @@ func (m *MsgMgo) findBeforeSendTime(ctx context.Context, conversationID string,
|
|||||||
limit := int64(-1)
|
limit := int64(-1)
|
||||||
if first {
|
if first {
|
||||||
first = false
|
first = false
|
||||||
limit = m.model.GetMsgIndex(seq)
|
limit = m.model.GetLimitForSingleDoc(seq)
|
||||||
}
|
}
|
||||||
docID := m.model.BuildDocIDByIndex(conversationID, i)
|
docID := m.model.BuildDocIDByIndex(conversationID, i)
|
||||||
msgSeq, msgSendTime, err := m.findBeforeDocSendTime(ctx, docID, limit)
|
msgSeq, msgSendTime, err := m.findBeforeDocSendTime(ctx, docID, limit)
|
||||||
|
@ -132,6 +132,10 @@ func (*MsgDocModel) GetMsgIndex(seq int64) int64 {
|
|||||||
return (seq - 1) % singleGocMsgNum
|
return (seq - 1) % singleGocMsgNum
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (*MsgDocModel) GetLimitForSingleDoc(seq int64) int64 {
|
||||||
|
return seq % singleGocMsgNum
|
||||||
|
}
|
||||||
|
|
||||||
func (*MsgDocModel) indexGen(conversationID string, seqSuffix int64) string {
|
func (*MsgDocModel) indexGen(conversationID string, seqSuffix int64) string {
|
||||||
return conversationID + ":" + strconv.FormatInt(seqSuffix, 10)
|
return conversationID + ":" + strconv.FormatInt(seqSuffix, 10)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user