Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update progress logic. #615

Merged
merged 28 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d1d029c
update trigger const.
mo3et Jul 22, 2024
8ecb177
feat: implement more accurate progress.
mo3et Jul 22, 2024
f01ecf2
Merge branch 'openimsdk:main' into fix/progress-in-reinstall
mo3et Jul 22, 2024
580f4a3
Merge branch 'main' of github.com:openimsdk/openim-sdk-core into fix/…
mo3et Jul 22, 2024
f68a02f
Merge branch 'fix/progress-in-reinstall' of github.com:mo3et/openim-s…
mo3et Jul 22, 2024
0c4a9a4
optimize method implement.
mo3et Jul 22, 2024
ce6a093
update conversation List logic.
mo3et Jul 22, 2024
5017cf6
update method logic.
mo3et Jul 22, 2024
b980b3a
update conversation logic.
mo3et Jul 22, 2024
887922b
update BatchInsertMessageList.
mo3et Jul 22, 2024
b711208
update addProgress to private.
mo3et Jul 22, 2024
fef5b5f
Merge branch 'main' of github.com:openimsdk/openim-sdk-core into fix/…
mo3et Jul 23, 2024
a220b3f
fix update loss contents.
mo3et Jul 24, 2024
f8471d8
update condition logic.
mo3et Jul 24, 2024
065b48e
fix: remove uncorrect use ctx.
mo3et Jul 24, 2024
cabb437
Merge branch 'main' of github.com:openimsdk/openim-sdk-core into fix/…
mo3et Jul 24, 2024
21c9084
remove unnecesary content.
mo3et Jul 24, 2024
5456963
fix:remove uncorrect log call.
mo3et Jul 24, 2024
1cea560
Merge branch 'main' of github.com:openimsdk/openim-sdk-core into fix/…
mo3et Jul 24, 2024
58f6178
fix uncorrect progress add.
mo3et Jul 24, 2024
f70620c
recovery.
mo3et Jul 24, 2024
2b7c2d6
fix: uncorrect map init.
mo3et Jul 25, 2024
4795d3c
feat: update progress logic.
mo3et Jul 25, 2024
9c6ac72
Merge branch 'main' of github.com:openimsdk/openim-sdk-core into fix/…
mo3et Jul 25, 2024
071f502
fix: use map to correct.
mo3et Jul 25, 2024
28b9dc6
add debug log comment.
mo3et Jul 25, 2024
b5320c1
update progress number implement.
mo3et Jul 25, 2024
0016089
update SyncProgress.
mo3et Jul 25, 2024
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
17 changes: 8 additions & 9 deletions internal/conversation_msg/conversation_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type Conversation struct {
full *full.Full
maxSeqRecorder MaxSeqRecorder
IsExternalExtensions bool
msgOffset int
progress int

startTime time.Time
Expand Down Expand Up @@ -119,6 +120,7 @@ func NewConversation(ctx context.Context, longConnMgr *interaction.LongConnMgr,
messageController: NewMessageController(db, ch),
IsExternalExtensions: info.IsExternalExtensions(),
maxSeqRecorder: NewMaxSeqRecorder(),
msgOffset: 0,
progress: 0,
}
n.typing = newTyping(n)
Expand Down Expand Up @@ -448,12 +450,13 @@ func (c *Conversation) doMsgSyncByReinstalled(c2v common.Cmd2Value) {
allMsg := c2v.Value.(sdk_struct.CmdMsgSyncInReinstall).Msgs
ctx := c2v.Ctx
msgLen := len(allMsg)
c.msgOffset += msgLen
total := c2v.Value.(sdk_struct.CmdMsgSyncInReinstall).Total

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

log.ZDebug(ctx, "message come here conversation ch", "conversation length", msgLen)
log.ZDebug(ctx, "message come here conversation ch in reinstalled", "conversation length", msgLen)
b := time.Now()

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

latestMsg = msg

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

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

func (c *Conversation) addProgress(progress int) {
func (c *Conversation) addInitProgress(progress int) {
c.progress += progress
if c.progress > 100 {
c.progress = 100
}
}

func (c *Conversation) getProgress() int {
return c.progress
}

func listToMap(list []*model_struct.LocalConversation, m map[string]*model_struct.LocalConversation) {
for _, v := range list {
m[v.ConversationID] = v
Expand Down
12 changes: 7 additions & 5 deletions internal/conversation_msg/conversation_notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ const (
asyncWait
)

// InitSyncProgress is initialize Sync when reinstall.
const InitSyncProgress = 10

func (c *Conversation) Work(c2v common.Cmd2Value) {
log.ZDebug(c2v.Ctx, "NotificationCmd start", "cmd", c2v.Cmd, "value", c2v.Value)
defer log.ZDebug(c2v.Ctx, "NotificationCmd end", "cmd", c2v.Cmd, "value", c2v.Value)
Expand All @@ -65,7 +68,6 @@ func (c *Conversation) Work(c2v common.Cmd2Value) {
func (c *Conversation) syncFlag(c2v common.Cmd2Value) {
ctx := c2v.Ctx
syncFlag := c2v.Value.(sdk_struct.CmdNewMsgComeToConversation).SyncFlag
initSyncBaseProgress := 5
switch syncFlag {
case constant.AppDataSyncStart:
log.ZDebug(ctx, "AppDataSyncStart")
Expand All @@ -76,17 +78,17 @@ func (c *Conversation) syncFlag(c2v common.Cmd2Value) {
c.friend.IncrSyncFriends,
}
runSyncFunctions(ctx, asyncWaitFunctions, asyncWait)
c.addProgress(initSyncBaseProgress)
c.ConversationListener().OnSyncServerProgress(c.getProgress()) // notify server current Progress
c.addInitProgress(InitSyncProgress * 4 / 10) // add 40% of InitSyncProgress as progress
c.ConversationListener().OnSyncServerProgress(c.progress) // notify server current Progress

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

asyncNoWaitFunctions := []func(c context.Context) error{
c.user.SyncLoginUserInfoWithoutNotice,
Expand Down
6 changes: 5 additions & 1 deletion internal/interaction/msg_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,11 @@ func (m *MsgSyncer) syncAndTriggerReinstallMsgs(ctx context.Context, seqMap map[
msgNum += int(oneConversationSyncNum)
}
if msgNum >= SplitPullMsgNum {
tpSeqMap := tempSeqMap
tpSeqMap := make(map[string][2]int64, len(tempSeqMap))
for k, v := range tempSeqMap {
tpSeqMap[k] = v
}

gr.Go(func() error {
resp, err := m.pullMsgBySeqRange(ctx, tpSeqMap, syncMsgNum)
if err != nil {
Expand Down
Loading