Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions internal/interaction/msg_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/db_interface"
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct"
"github.com/openimsdk/openim-sdk-core/v3/sdk_struct"
"github.com/openimsdk/tools/errs"

"github.com/openimsdk/protocol/sdkws"
"github.com/openimsdk/tools/log"
Expand Down Expand Up @@ -81,6 +82,7 @@ func (m *MsgSyncer) loadSeq(ctx context.Context) error {
}

// TODO With a large number of sessions, this could potentially cause blocking and needs optimization.

type SyncedSeq struct {
ConversationID string
MaxSyncedSeq int64
Expand All @@ -105,7 +107,7 @@ func (m *MsgSyncer) loadSeq(ctx context.Context) error {
go func(i, start, end int) {
defer wg.Done()
for _, v := range conversationIDList[start:end] {
maxSyncedSeq, err := m.db.GetConversationNormalMsgSeqNoInit(ctx, v)
maxSyncedSeq, err := m.db.CheckConversationNormalMsgSeq(ctx, v)
resultMaps[i][v] = SyncedSeq{
ConversationID: v,
MaxSyncedSeq: maxSyncedSeq,
Expand All @@ -121,7 +123,7 @@ func (m *MsgSyncer) loadSeq(ctx context.Context) error {
for _, resultMap := range resultMaps {
for k, v := range resultMap {
if v.Err != nil {
log.ZError(ctx, "get group normal seq failed", v.Err, "conversationID", k)
log.ZError(ctx, "get group normal seq failed", errs.Wrap(v.Err), "conversationID", k)
continue
}
m.syncedMaxSeqs[k] = v.MaxSyncedSeq
Expand Down
14 changes: 10 additions & 4 deletions pkg/db/chat_log_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ func (d *DataBase) SearchMessageByKeyword(ctx context.Context, contentType []int
condition += subCondition
err = errs.WrapMsg(d.conn.WithContext(ctx).Table(utils.GetTableName(conversationID)).Where(condition, contentType).Order("send_time DESC").Offset(offset).Limit(count).Find(&result).Error, "InsertMessage failed")
return result, err
} // SearchMessageByContentTypeAndKeyword searches for messages in the database that match specified content types and keywords within a given time range.
}

// SearchMessageByContentTypeAndKeyword searches for messages in the database that match specified content types and keywords within a given time range.
func (d *DataBase) SearchMessageByContentTypeAndKeyword(ctx context.Context, contentType []int, conversationID string, keywordList []string, keywordListMatchType int, startTime, endTime int64) (result []*model_struct.LocalChatLog, err error) {
var condition string
var subCondition string
Expand Down Expand Up @@ -385,10 +387,14 @@ func (d *DataBase) GetConversationNormalMsgSeq(ctx context.Context, conversation
return seq, errs.WrapMsg(err, "GetConversationNormalMsgSeq")
}

func (d *DataBase) GetConversationNormalMsgSeqNoInit(ctx context.Context, conversationID string) (int64, error) {
func (d *DataBase) CheckConversationNormalMsgSeq(ctx context.Context, conversationID string) (int64, error) {
var seq int64
err := d.conn.WithContext(ctx).Table(utils.GetConversationTableName(conversationID)).Select("IFNULL(max(seq),0)").Find(&seq).Error
return seq, errs.WrapMsg(err, "GetConversationNormalMsgSeq")

if d.tableChecker.HasTable(utils.GetConversationTableName(conversationID)) {
err := d.conn.WithContext(ctx).Table(utils.GetConversationTableName(conversationID)).Select("IFNULL(max(seq),0)").Find(&seq).Error
return seq, errs.Wrap(err)
}
return 0, nil
}

func (d *DataBase) GetConversationPeerNormalMsgSeq(ctx context.Context, conversationID string) (int64, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/db/db_interface/databse.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ type MessageModel interface {
GetMessagesByClientMsgIDs(ctx context.Context, conversationID string, msgIDs []string) (result []*model_struct.LocalChatLog, err error)
GetMessagesBySeqs(ctx context.Context, conversationID string, seqs []int64) (result []*model_struct.LocalChatLog, err error)
GetConversationNormalMsgSeq(ctx context.Context, conversationID string) (int64, error)
GetConversationNormalMsgSeqNoInit(ctx context.Context, conversationID string) (int64, error)
CheckConversationNormalMsgSeq(ctx context.Context, conversationID string) (int64, error)
GetConversationPeerNormalMsgSeq(ctx context.Context, conversationID string) (int64, error)

UpdateMsgSenderNickname(ctx context.Context, sendID, nickname string, sType int) error
Expand Down
2 changes: 1 addition & 1 deletion wasm/indexdb/chat_log_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ func (i *LocalChatLogs) GetConversationNormalMsgSeq(ctx context.Context, convers
}
}

func (i *LocalChatLogs) GetConversationNormalMsgSeqNoInit(ctx context.Context, conversationID string) (int64, error) {
func (i *LocalChatLogs) CheckConversationNormalMsgSeq(ctx context.Context, conversationID string) (int64, error) {
seq, err := exec.Exec(conversationID)
if err != nil {
return 0, err
Expand Down