fix: reinstall app sync data split.
This commit is contained in:
@@ -38,7 +38,6 @@ func (c *Conversation) Work(c2v common.Cmd2Value) {
|
||||
switch c2v.Cmd {
|
||||
case constant.CmdNewMsgCome:
|
||||
c.doMsgNew(c2v)
|
||||
case constant.CmdSuperGroupMsgCome:
|
||||
case constant.CmdUpdateConversation:
|
||||
c.doUpdateConversation(c2v)
|
||||
case constant.CmdUpdateMessage:
|
||||
@@ -54,26 +53,54 @@ func (c *Conversation) doNotificationNew(c2v common.Cmd2Value) {
|
||||
allMsg := c2v.Value.(sdk_struct.CmdNewMsgComeToConversation).Msgs
|
||||
syncFlag := c2v.Value.(sdk_struct.CmdNewMsgComeToConversation).SyncFlag
|
||||
switch syncFlag {
|
||||
case constant.MsgSyncBegin:
|
||||
case constant.AppDataSyncStart:
|
||||
log.ZDebug(ctx, "AppDataSyncStart")
|
||||
c.startTime = time.Now()
|
||||
c.ConversationListener().OnSyncServerStart()
|
||||
if err := c.SyncAllConversationHashReadSeqs(ctx); err != nil {
|
||||
log.ZError(ctx, "SyncConversationHashReadSeqs err", err)
|
||||
c.ConversationListener().OnSyncServerStart(true)
|
||||
syncFunctions := []func(c context.Context) error{
|
||||
c.SyncAllConversationHashReadSeqs,
|
||||
c.user.SyncLoginUserInfoWithoutNotice,
|
||||
c.friend.SyncAllBlackListWithoutNotice,
|
||||
c.friend.SyncAllFriendApplicationWithoutNotice,
|
||||
c.friend.SyncAllSelfFriendApplicationWithoutNotice,
|
||||
c.group.SyncAllAdminGroupApplicationWithoutNotice,
|
||||
c.group.SyncAllSelfGroupApplicationWithoutNotice,
|
||||
c.user.SyncAllCommandWithoutNotice,
|
||||
c.group.SyncAllJoinedGroupsAndMembers,
|
||||
c.friend.IncrSyncFriends,
|
||||
c.SyncAllConversationsWithoutNotice,
|
||||
}
|
||||
totalFunctions := len(syncFunctions)
|
||||
for i, syncFunc := range syncFunctions {
|
||||
funcName := runtime.FuncForPC(reflect.ValueOf(syncFunc).Pointer()).Name()
|
||||
startTime := time.Now()
|
||||
err := syncFunc(ctx)
|
||||
duration := time.Since(startTime)
|
||||
if err != nil {
|
||||
log.ZWarn(ctx, fmt.Sprintf("%s sync err", funcName), err, "duration", duration.Seconds())
|
||||
} else {
|
||||
log.ZDebug(ctx, fmt.Sprintf("%s completed successfully", funcName), "duration", duration.Seconds())
|
||||
}
|
||||
progress := int(float64(i+1) / float64(totalFunctions) * 100)
|
||||
if progress == 0 {
|
||||
progress = 1
|
||||
}
|
||||
c.ConversationListener().OnSyncServerProgress(progress)
|
||||
}
|
||||
case constant.AppDataSyncFinish:
|
||||
log.ZDebug(ctx, "AppDataSyncFinish", "time", time.Since(c.startTime).Milliseconds())
|
||||
c.ConversationListener().OnSyncServerFailed(true)
|
||||
case constant.MsgSyncBegin:
|
||||
log.ZDebug(ctx, "MsgSyncBegin")
|
||||
c.startTime = time.Now()
|
||||
c.ConversationListener().OnSyncServerStart(false)
|
||||
//clear SubscriptionStatusMap
|
||||
c.user.OnlineStatusCache.DeleteAll()
|
||||
for _, syncFunc := range []func(c context.Context) error{
|
||||
c.user.SyncLoginUserInfo,
|
||||
c.friend.SyncAllBlackList, c.friend.SyncAllFriendApplication, c.friend.SyncAllSelfFriendApplication,
|
||||
c.group.SyncAllAdminGroupApplication, c.group.SyncAllSelfGroupApplication, c.user.SyncAllCommand,
|
||||
} {
|
||||
go func(syncFunc func(c context.Context) error) {
|
||||
_ = syncFunc(ctx)
|
||||
}(syncFunc)
|
||||
}
|
||||
|
||||
syncFunctions := []func(c context.Context) error{
|
||||
c.group.SyncAllJoinedGroupsAndMembers, c.friend.IncrSyncFriends, c.SyncAllConversations,
|
||||
c.SyncAllConversationHashReadSeqs,
|
||||
c.group.SyncAllJoinedGroupsAndMembers,
|
||||
c.friend.IncrSyncFriends,
|
||||
}
|
||||
|
||||
for _, syncFunc := range syncFunctions {
|
||||
@@ -87,11 +114,29 @@ func (c *Conversation) doNotificationNew(c2v common.Cmd2Value) {
|
||||
log.ZDebug(ctx, fmt.Sprintf("%s completed successfully", funcName), "duration", duration.Seconds())
|
||||
}
|
||||
}
|
||||
for _, syncFunc := range []func(c context.Context) error{
|
||||
c.user.SyncLoginUserInfo,
|
||||
c.friend.SyncAllBlackList, c.friend.SyncAllFriendApplication, c.friend.SyncAllSelfFriendApplication,
|
||||
c.group.SyncAllAdminGroupApplication, c.group.SyncAllSelfGroupApplication, c.user.SyncAllCommand, c.SyncAllConversations,
|
||||
} {
|
||||
go func(syncFunc func(c context.Context) error) {
|
||||
funcName := runtime.FuncForPC(reflect.ValueOf(syncFunc).Pointer()).Name()
|
||||
startTime := time.Now()
|
||||
err := syncFunc(ctx)
|
||||
duration := time.Since(startTime)
|
||||
if err != nil {
|
||||
log.ZWarn(ctx, fmt.Sprintf("%s sync err", funcName), err, "duration", duration.Seconds())
|
||||
} else {
|
||||
log.ZDebug(ctx, fmt.Sprintf("%s completed successfully", funcName), "duration", duration.Seconds())
|
||||
}
|
||||
}(syncFunc)
|
||||
}
|
||||
|
||||
case constant.MsgSyncFailed:
|
||||
c.ConversationListener().OnSyncServerFailed()
|
||||
c.ConversationListener().OnSyncServerFailed(false)
|
||||
case constant.MsgSyncEnd:
|
||||
log.ZDebug(ctx, "MsgSyncEnd", "time", time.Since(c.startTime).Milliseconds())
|
||||
defer c.ConversationListener().OnSyncServerFinish()
|
||||
c.ConversationListener().OnSyncServerFinish(false)
|
||||
}
|
||||
|
||||
for conversationID, msgs := range allMsg {
|
||||
|
||||
@@ -50,7 +50,7 @@ func (m *MessageController) BatchUpdateMessageList(ctx context.Context, updateMs
|
||||
latestMsg := &sdk_struct.MsgStruct{}
|
||||
if err := json.Unmarshal([]byte(conversation.LatestMsg), latestMsg); err != nil {
|
||||
log.ZError(ctx, "Unmarshal err", err, "conversationID",
|
||||
conversationID, "latestMsg", conversation.LatestMsg)
|
||||
conversationID, "latestMsg", conversation.LatestMsg, "messages", messages)
|
||||
continue
|
||||
}
|
||||
for _, v := range messages {
|
||||
|
||||
@@ -54,6 +54,16 @@ func (c *Conversation) SyncConversations(ctx context.Context, conversationIDs []
|
||||
}
|
||||
|
||||
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()
|
||||
conversationsOnServer, err := c.getServerConversationList(ctx)
|
||||
if err != nil {
|
||||
@@ -64,25 +74,34 @@ func (c *Conversation) SyncAllConversations(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (c *Conversation) SyncAllConversationHashReadSeqs(ctx context.Context) error {
|
||||
startTime := time.Now()
|
||||
log.ZDebug(ctx, "start SyncConversationHashReadSeqs")
|
||||
|
||||
seqs, err := c.getServerHasReadAndMaxSeqs(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.ZDebug(ctx, "getServerHasReadAndMaxSeqs completed", "duration", time.Since(startTime).Seconds())
|
||||
|
||||
if len(seqs) == 0 {
|
||||
return nil
|
||||
}
|
||||
var conversationChangedIDs []string
|
||||
var conversationIDsNeedSync []string
|
||||
|
||||
stepStartTime := time.Now()
|
||||
conversationsOnLocal, err := c.db.GetAllConversations(ctx)
|
||||
if err != nil {
|
||||
log.ZWarn(ctx, "get all conversations err", err)
|
||||
return err
|
||||
}
|
||||
log.ZDebug(ctx, "GetAllConversations completed", "duration", time.Since(stepStartTime).Seconds())
|
||||
|
||||
conversationsOnLocalMap := datautil.SliceToMap(conversationsOnLocal, func(e *model_struct.LocalConversation) string {
|
||||
return e.ConversationID
|
||||
})
|
||||
|
||||
stepStartTime = time.Now()
|
||||
for conversationID, v := range seqs {
|
||||
var unreadCount int32
|
||||
c.maxSeqRecorder.Set(conversationID, v.MaxSeq)
|
||||
@@ -104,18 +123,24 @@ func (c *Conversation) SyncAllConversationHashReadSeqs(ctx context.Context) erro
|
||||
} else {
|
||||
conversationIDsNeedSync = append(conversationIDsNeedSync, conversationID)
|
||||
}
|
||||
|
||||
}
|
||||
log.ZDebug(ctx, "Process seqs completed", "duration", time.Since(stepStartTime).Seconds())
|
||||
|
||||
if len(conversationIDsNeedSync) > 0 {
|
||||
stepStartTime = time.Now()
|
||||
conversationsOnServer, err := c.getServerConversationsByIDs(ctx, conversationIDsNeedSync)
|
||||
if err != nil {
|
||||
log.ZWarn(ctx, "getServerConversationsByIDs err", err, "conversationIDs", conversationIDsNeedSync)
|
||||
return err
|
||||
}
|
||||
log.ZDebug(ctx, "getServerConversationsByIDs completed", "duration", time.Since(stepStartTime).Seconds())
|
||||
|
||||
stepStartTime = time.Now()
|
||||
if err := c.batchAddFaceURLAndName(ctx, conversationsOnServer...); err != nil {
|
||||
log.ZWarn(ctx, "batchAddFaceURLAndName err", err, "conversationsOnServer", conversationsOnServer)
|
||||
return err
|
||||
}
|
||||
log.ZDebug(ctx, "batchAddFaceURLAndName completed", "duration", time.Since(stepStartTime).Seconds())
|
||||
|
||||
for _, conversation := range conversationsOnServer {
|
||||
var unreadCount int32
|
||||
@@ -132,17 +157,23 @@ func (c *Conversation) SyncAllConversationHashReadSeqs(ctx context.Context) erro
|
||||
conversation.UnreadCount = unreadCount
|
||||
conversation.HasReadSeq = v.HasReadSeq
|
||||
}
|
||||
|
||||
stepStartTime = time.Now()
|
||||
err = c.db.BatchInsertConversationList(ctx, conversationsOnServer)
|
||||
if err != nil {
|
||||
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)
|
||||
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.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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user