Skip to content

Commit 32cc2e6

Browse files
authored
feat: update progress logic. (#615)
* update trigger const. * feat: implement more accurate progress. * optimize method implement. * update conversation List logic. * update method logic. * update conversation logic. * update BatchInsertMessageList. * update addProgress to private. * fix update loss contents. * update condition logic. * fix: remove uncorrect use ctx. * remove unnecesary content. * fix:remove uncorrect log call. * fix uncorrect progress add. * recovery. * fix: uncorrect map init. * feat: update progress logic. * fix: use map to correct. * add debug log comment. * update progress number implement. * update SyncProgress.
1 parent d07fab9 commit 32cc2e6

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

internal/conversation_msg/conversation_msg.go

+8-9
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ type Conversation struct {
8181
full *full.Full
8282
maxSeqRecorder MaxSeqRecorder
8383
IsExternalExtensions bool
84+
msgOffset int
8485
progress int
8586

8687
startTime time.Time
@@ -119,6 +120,7 @@ func NewConversation(ctx context.Context, longConnMgr *interaction.LongConnMgr,
119120
messageController: NewMessageController(db, ch),
120121
IsExternalExtensions: info.IsExternalExtensions(),
121122
maxSeqRecorder: NewMaxSeqRecorder(),
123+
msgOffset: 0,
122124
progress: 0,
123125
}
124126
n.typing = newTyping(n)
@@ -448,12 +450,13 @@ func (c *Conversation) doMsgSyncByReinstalled(c2v common.Cmd2Value) {
448450
allMsg := c2v.Value.(sdk_struct.CmdMsgSyncInReinstall).Msgs
449451
ctx := c2v.Ctx
450452
msgLen := len(allMsg)
453+
c.msgOffset += msgLen
451454
total := c2v.Value.(sdk_struct.CmdMsgSyncInReinstall).Total
452455

453456
insertMsg := make(map[string][]*model_struct.LocalChatLog, 10)
454457
conversationList := make([]*model_struct.LocalConversation, 0)
455458

456-
log.ZDebug(ctx, "message come here conversation ch", "conversation length", msgLen)
459+
log.ZDebug(ctx, "message come here conversation ch in reinstalled", "conversation length", msgLen)
457460
b := time.Now()
458461

459462
for conversationID, msgs := range allMsg {
@@ -497,7 +500,7 @@ func (c *Conversation) doMsgSyncByReinstalled(c2v common.Cmd2Value) {
497500
log.ZDebug(ctx, "decode message", "msg", msg)
498501
if v.SendID == c.loginUserID {
499502
// Messages sent by myself //if sent through this terminal
500-
log.ZInfo(ctx, "sync message", "msg", msg)
503+
log.ZInfo(ctx, "sync message in reinstalled", "msg", msg)
501504

502505
latestMsg = msg
503506

@@ -531,21 +534,17 @@ func (c *Conversation) doMsgSyncByReinstalled(c2v common.Cmd2Value) {
531534
}
532535
log.ZDebug(ctx, "before trigger msg", "cost time", time.Since(b).Seconds(), "len", len(allMsg))
533536

534-
c.addProgress((msgLen * 90) / total)
535-
c.ConversationListener().OnSyncServerProgress(c.getProgress())
537+
// log.ZDebug(ctx, "progress is", "msgLen", msgLen, "msgOffset", c.msgOffset, "total", total, "now progress is", (c.msgOffset*(100-InitSyncProgress))/total + InitSyncProgress)
538+
c.ConversationListener().OnSyncServerProgress((c.msgOffset*(100-InitSyncProgress))/total + InitSyncProgress)
536539
}
537540

538-
func (c *Conversation) addProgress(progress int) {
541+
func (c *Conversation) addInitProgress(progress int) {
539542
c.progress += progress
540543
if c.progress > 100 {
541544
c.progress = 100
542545
}
543546
}
544547

545-
func (c *Conversation) getProgress() int {
546-
return c.progress
547-
}
548-
549548
func listToMap(list []*model_struct.LocalConversation, m map[string]*model_struct.LocalConversation) {
550549
for _, v := range list {
551550
m[v.ConversationID] = v

internal/conversation_msg/conversation_notification.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ const (
4040
asyncWait
4141
)
4242

43+
// InitSyncProgress is initialize Sync when reinstall.
44+
const InitSyncProgress = 10
45+
4346
func (c *Conversation) Work(c2v common.Cmd2Value) {
4447
log.ZDebug(c2v.Ctx, "NotificationCmd start", "cmd", c2v.Cmd, "value", c2v.Value)
4548
defer log.ZDebug(c2v.Ctx, "NotificationCmd end", "cmd", c2v.Cmd, "value", c2v.Value)
@@ -65,28 +68,28 @@ func (c *Conversation) Work(c2v common.Cmd2Value) {
6568
func (c *Conversation) syncFlag(c2v common.Cmd2Value) {
6669
ctx := c2v.Ctx
6770
syncFlag := c2v.Value.(sdk_struct.CmdNewMsgComeToConversation).SyncFlag
68-
initSyncBaseProgress := 5
6971
switch syncFlag {
7072
case constant.AppDataSyncStart:
7173
log.ZDebug(ctx, "AppDataSyncStart")
7274
c.startTime = time.Now()
7375
c.ConversationListener().OnSyncServerStart(true)
76+
c.ConversationListener().OnSyncServerProgress(1)
7477
asyncWaitFunctions := []func(c context.Context) error{
7578
c.group.SyncAllJoinedGroupsAndMembers,
7679
c.friend.IncrSyncFriends,
7780
}
7881
runSyncFunctions(ctx, asyncWaitFunctions, asyncWait)
79-
c.addProgress(initSyncBaseProgress)
80-
c.ConversationListener().OnSyncServerProgress(c.getProgress()) // notify server current Progress
82+
c.addInitProgress(InitSyncProgress * 4 / 10) // add 40% of InitSyncProgress as progress
83+
c.ConversationListener().OnSyncServerProgress(c.progress) // notify server current Progress
8184

8285
syncWaitFunctions := []func(c context.Context) error{
8386
c.IncrSyncConversations,
8487
c.SyncAllConversationHashReadSeqs,
8588
}
8689
runSyncFunctions(ctx, syncWaitFunctions, syncWait)
8790
log.ZWarn(ctx, "core data sync over", nil, "cost time", time.Since(c.startTime).Seconds())
88-
c.addProgress(initSyncBaseProgress)
89-
c.ConversationListener().OnSyncServerProgress(c.getProgress()) // notify server current Progress
91+
c.addInitProgress(InitSyncProgress * 6 / 10) // add 60% of InitSyncProgress as progress
92+
c.ConversationListener().OnSyncServerProgress(c.progress) // notify server current Progress
9093

9194
asyncNoWaitFunctions := []func(c context.Context) error{
9295
c.user.SyncLoginUserInfoWithoutNotice,

internal/interaction/msg_sync.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,11 @@ func (m *MsgSyncer) syncAndTriggerReinstallMsgs(ctx context.Context, seqMap map[
398398
msgNum += int(oneConversationSyncNum)
399399
}
400400
if msgNum >= SplitPullMsgNum {
401-
tpSeqMap := tempSeqMap
401+
tpSeqMap := make(map[string][2]int64, len(tempSeqMap))
402+
for k, v := range tempSeqMap {
403+
tpSeqMap[k] = v
404+
}
405+
402406
gr.Go(func() error {
403407
resp, err := m.pullMsgBySeqRange(ctx, tpSeqMap, syncMsgNum)
404408
if err != nil {

0 commit comments

Comments
 (0)