|
|
@ -16,8 +16,11 @@ package interaction |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"context" |
|
|
|
"context" |
|
|
|
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct" |
|
|
|
|
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
|
|
|
|
"sync" |
|
|
|
|
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/openimsdk/openim-sdk-core/v3/pkg/db/model_struct" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/openimsdk/openim-sdk-core/v3/pkg/common" |
|
|
|
"github.com/openimsdk/openim-sdk-core/v3/pkg/common" |
|
|
|
"github.com/openimsdk/openim-sdk-core/v3/pkg/constant" |
|
|
|
"github.com/openimsdk/openim-sdk-core/v3/pkg/constant" |
|
|
@ -78,15 +81,51 @@ func (m *MsgSyncer) loadSeq(ctx context.Context) error { |
|
|
|
if len(conversationIDList) == 0 { |
|
|
|
if len(conversationIDList) == 0 { |
|
|
|
m.reinstalled = true |
|
|
|
m.reinstalled = true |
|
|
|
} |
|
|
|
} |
|
|
|
//TODO With a large number of sessions, this could potentially cause blocking and needs optimization.
|
|
|
|
|
|
|
|
|
|
|
|
// TODO With a large number of sessions, this could potentially cause blocking and needs optimization.
|
|
|
|
|
|
|
|
type SyncedSeq struct { |
|
|
|
|
|
|
|
ConversationID string |
|
|
|
|
|
|
|
MaxSyncedSeq int64 |
|
|
|
|
|
|
|
Err error |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
concurrency := 10 |
|
|
|
|
|
|
|
t2 := time.Now() |
|
|
|
|
|
|
|
SyncedSeqs := make(chan SyncedSeq, len(conversationIDList)) |
|
|
|
|
|
|
|
sem := make(chan struct{}, concurrency) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var wg sync.WaitGroup |
|
|
|
for _, v := range conversationIDList { |
|
|
|
for _, v := range conversationIDList { |
|
|
|
maxSyncedSeq, err := m.db.GetConversationNormalMsgSeq(ctx, v) |
|
|
|
wg.Add(1) |
|
|
|
if err != nil { |
|
|
|
sem <- struct{}{} // Acquire a token
|
|
|
|
log.ZError(ctx, "get group normal seq failed", err, "conversationID", v) |
|
|
|
go func(conversationID string) { |
|
|
|
|
|
|
|
defer wg.Done() |
|
|
|
|
|
|
|
defer func() { <-sem }() // Release the token
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
maxSyncedSeq, err := m.db.GetConversationNormalMsgSeq(ctx, conversationID) |
|
|
|
|
|
|
|
SyncedSeqs <- SyncedSeq{ |
|
|
|
|
|
|
|
ConversationID: conversationID, |
|
|
|
|
|
|
|
MaxSyncedSeq: maxSyncedSeq, |
|
|
|
|
|
|
|
Err: err, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}(v) |
|
|
|
|
|
|
|
log.ZDebug(ctx, "goroutine done.", "goroutine cost time", time.Since(t2)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Close the results channel once all goroutines have finished
|
|
|
|
|
|
|
|
go func() { |
|
|
|
|
|
|
|
wg.Wait() |
|
|
|
|
|
|
|
close(SyncedSeqs) |
|
|
|
|
|
|
|
}() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Collect the results
|
|
|
|
|
|
|
|
for res := range SyncedSeqs { |
|
|
|
|
|
|
|
if res.Err != nil { |
|
|
|
|
|
|
|
log.ZError(ctx, "get group normal seq failed", res.Err, "conversationID", res.ConversationID) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
m.syncedMaxSeqs[v] = maxSyncedSeq |
|
|
|
m.syncedMaxSeqs[res.ConversationID] = res.MaxSyncedSeq |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
notificationSeqs, err := m.db.GetNotificationAllSeqs(ctx) |
|
|
|
notificationSeqs, err := m.db.GetNotificationAllSeqs(ctx) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.ZError(ctx, "get notification seq failed", err) |
|
|
|
log.ZError(ctx, "get notification seq failed", err) |
|
|
@ -246,7 +285,7 @@ func (m *MsgSyncer) doConnected(ctx context.Context) { |
|
|
|
common.TriggerCmdNotification(m.ctx, sdk_struct.CmdNewMsgComeToConversation{SyncFlag: constant.MsgSyncFailed}, m.conversationCh) |
|
|
|
common.TriggerCmdNotification(m.ctx, sdk_struct.CmdNewMsgComeToConversation{SyncFlag: constant.MsgSyncFailed}, m.conversationCh) |
|
|
|
return |
|
|
|
return |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
log.ZDebug(m.ctx, "get max seq success", "resp", resp) |
|
|
|
log.ZDebug(m.ctx, "get max seq success", "resp", resp.MaxSeqs) |
|
|
|
} |
|
|
|
} |
|
|
|
m.compareSeqsAndBatchSync(ctx, resp.MaxSeqs, connectPullNums) |
|
|
|
m.compareSeqsAndBatchSync(ctx, resp.MaxSeqs, connectPullNums) |
|
|
|
if reinstalled { |
|
|
|
if reinstalled { |
|
|
|