|
|
@ -54,6 +54,16 @@ func (c *Conversation) SyncConversations(ctx context.Context, conversationIDs [] |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (c *Conversation) SyncAllConversations(ctx context.Context) error { |
|
|
|
func (c *Conversation) SyncAllConversations(ctx context.Context) error { |
|
|
|
|
|
|
|
ccTime := time.Now() |
|
|
|
|
|
|
|
conversationsOnServer, err := c.getServerConversationList(ctx) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
log.ZDebug(ctx, "get server cost time", "cost time", time.Since(ccTime), "conversation on server", conversationsOnServer) |
|
|
|
|
|
|
|
return c.SyncConversationsAndTriggerCallback(ctx, conversationsOnServer, false) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (c *Conversation) SyncAllConversationsWithoutNotice(ctx context.Context) error { |
|
|
|
ccTime := time.Now() |
|
|
|
ccTime := time.Now() |
|
|
|
conversationsOnServer, err := c.getServerConversationList(ctx) |
|
|
|
conversationsOnServer, err := c.getServerConversationList(ctx) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
@ -64,25 +74,34 @@ func (c *Conversation) SyncAllConversations(ctx context.Context) error { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (c *Conversation) SyncAllConversationHashReadSeqs(ctx context.Context) error { |
|
|
|
func (c *Conversation) SyncAllConversationHashReadSeqs(ctx context.Context) error { |
|
|
|
|
|
|
|
startTime := time.Now() |
|
|
|
log.ZDebug(ctx, "start SyncConversationHashReadSeqs") |
|
|
|
log.ZDebug(ctx, "start SyncConversationHashReadSeqs") |
|
|
|
|
|
|
|
|
|
|
|
seqs, err := c.getServerHasReadAndMaxSeqs(ctx) |
|
|
|
seqs, err := c.getServerHasReadAndMaxSeqs(ctx) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
log.ZDebug(ctx, "getServerHasReadAndMaxSeqs completed", "duration", time.Since(startTime).Seconds()) |
|
|
|
|
|
|
|
|
|
|
|
if len(seqs) == 0 { |
|
|
|
if len(seqs) == 0 { |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|
var conversationChangedIDs []string |
|
|
|
var conversationChangedIDs []string |
|
|
|
var conversationIDsNeedSync []string |
|
|
|
var conversationIDsNeedSync []string |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stepStartTime := time.Now() |
|
|
|
conversationsOnLocal, err := c.db.GetAllConversations(ctx) |
|
|
|
conversationsOnLocal, err := c.db.GetAllConversations(ctx) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.ZWarn(ctx, "get all conversations err", err) |
|
|
|
log.ZWarn(ctx, "get all conversations err", err) |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
log.ZDebug(ctx, "GetAllConversations completed", "duration", time.Since(stepStartTime).Seconds()) |
|
|
|
|
|
|
|
|
|
|
|
conversationsOnLocalMap := datautil.SliceToMap(conversationsOnLocal, func(e *model_struct.LocalConversation) string { |
|
|
|
conversationsOnLocalMap := datautil.SliceToMap(conversationsOnLocal, func(e *model_struct.LocalConversation) string { |
|
|
|
return e.ConversationID |
|
|
|
return e.ConversationID |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stepStartTime = time.Now() |
|
|
|
for conversationID, v := range seqs { |
|
|
|
for conversationID, v := range seqs { |
|
|
|
var unreadCount int32 |
|
|
|
var unreadCount int32 |
|
|
|
c.maxSeqRecorder.Set(conversationID, v.MaxSeq) |
|
|
|
c.maxSeqRecorder.Set(conversationID, v.MaxSeq) |
|
|
@ -104,18 +123,24 @@ func (c *Conversation) SyncAllConversationHashReadSeqs(ctx context.Context) erro |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
conversationIDsNeedSync = append(conversationIDsNeedSync, conversationID) |
|
|
|
conversationIDsNeedSync = append(conversationIDsNeedSync, conversationID) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
log.ZDebug(ctx, "Process seqs completed", "duration", time.Since(stepStartTime).Seconds()) |
|
|
|
|
|
|
|
|
|
|
|
if len(conversationIDsNeedSync) > 0 { |
|
|
|
if len(conversationIDsNeedSync) > 0 { |
|
|
|
|
|
|
|
stepStartTime = time.Now() |
|
|
|
conversationsOnServer, err := c.getServerConversationsByIDs(ctx, conversationIDsNeedSync) |
|
|
|
conversationsOnServer, err := c.getServerConversationsByIDs(ctx, conversationIDsNeedSync) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.ZWarn(ctx, "getServerConversationsByIDs err", err, "conversationIDs", conversationIDsNeedSync) |
|
|
|
log.ZWarn(ctx, "getServerConversationsByIDs err", err, "conversationIDs", conversationIDsNeedSync) |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
log.ZDebug(ctx, "getServerConversationsByIDs completed", "duration", time.Since(stepStartTime).Seconds()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stepStartTime = time.Now() |
|
|
|
if err := c.batchAddFaceURLAndName(ctx, conversationsOnServer...); err != nil { |
|
|
|
if err := c.batchAddFaceURLAndName(ctx, conversationsOnServer...); err != nil { |
|
|
|
log.ZWarn(ctx, "batchAddFaceURLAndName err", err, "conversationsOnServer", conversationsOnServer) |
|
|
|
log.ZWarn(ctx, "batchAddFaceURLAndName err", err, "conversationsOnServer", conversationsOnServer) |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
log.ZDebug(ctx, "batchAddFaceURLAndName completed", "duration", time.Since(stepStartTime).Seconds()) |
|
|
|
|
|
|
|
|
|
|
|
for _, conversation := range conversationsOnServer { |
|
|
|
for _, conversation := range conversationsOnServer { |
|
|
|
var unreadCount int32 |
|
|
|
var unreadCount int32 |
|
|
@ -132,17 +157,23 @@ func (c *Conversation) SyncAllConversationHashReadSeqs(ctx context.Context) erro |
|
|
|
conversation.UnreadCount = unreadCount |
|
|
|
conversation.UnreadCount = unreadCount |
|
|
|
conversation.HasReadSeq = v.HasReadSeq |
|
|
|
conversation.HasReadSeq = v.HasReadSeq |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stepStartTime = time.Now() |
|
|
|
err = c.db.BatchInsertConversationList(ctx, conversationsOnServer) |
|
|
|
err = c.db.BatchInsertConversationList(ctx, conversationsOnServer) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
log.ZWarn(ctx, "BatchInsertConversationList err", err, "conversationsOnServer", conversationsOnServer) |
|
|
|
log.ZWarn(ctx, "BatchInsertConversationList err", err, "conversationsOnServer", conversationsOnServer) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
log.ZDebug(ctx, "BatchInsertConversationList completed", "duration", time.Since(stepStartTime).Seconds()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
log.ZDebug(ctx, "update conversations", "conversations", conversationChangedIDs) |
|
|
|
log.ZDebug(ctx, "update conversations", "conversations", conversationChangedIDs) |
|
|
|
if len(conversationChangedIDs) > 0 { |
|
|
|
if len(conversationChangedIDs) > 0 { |
|
|
|
|
|
|
|
stepStartTime = time.Now() |
|
|
|
common.TriggerCmdUpdateConversation(ctx, common.UpdateConNode{Action: constant.ConChange, Args: conversationChangedIDs}, c.GetCh()) |
|
|
|
common.TriggerCmdUpdateConversation(ctx, common.UpdateConNode{Action: constant.ConChange, Args: conversationChangedIDs}, c.GetCh()) |
|
|
|
common.TriggerCmdUpdateConversation(ctx, common.UpdateConNode{Action: constant.TotalUnreadMessageChanged}, c.GetCh()) |
|
|
|
common.TriggerCmdUpdateConversation(ctx, common.UpdateConNode{Action: constant.TotalUnreadMessageChanged}, c.GetCh()) |
|
|
|
|
|
|
|
log.ZDebug(ctx, "TriggerCmdUpdateConversation completed", "duration", time.Since(stepStartTime).Seconds()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.ZDebug(ctx, "SyncAllConversationHashReadSeqs completed", "totalDuration", time.Since(startTime).Seconds()) |
|
|
|
return nil |
|
|
|
return nil |
|
|
|
} |
|
|
|
} |
|
|
|