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

Add estimated sync time to progress state #245

Conversation

ZIMkaRU
Copy link
Member

@ZIMkaRU ZIMkaRU commented Jan 2, 2023

This PR adds estimated sync time to the progress state and changes corresponding test coverage. The idea:

  • on the backend side, make a rough estimate based on the elapsed time since sync started and the current sync percentage, check this example:
;(async () => {
const syncStartedAt = Date.now()

// some sync operations
await new Promise(resolve => setTimeout(resolve, 3000))

const progress = 0.23 // 23%, for example
const spentTime = Date.now() - syncStartedAt
const leftTime = (spentTime / progress) * (1 - progress)

// await this.wsEventEmitter.emit(leftTime)
console.log('[leftTime]:', leftTime)
})()
  • backend would emit estimated time by WS, also available to get current state using getSyncProgress endpoint, check below a description of returning data
  • show on UI estimated time, there need to think about where there's an appropriate place to show more sync info

Breaking changes:
getSyncProgress endpoint and emitProgress WS event return the following data structure:

{
 progress, // as previously value
 syncStartedAt, // null || millisecond timestamp, e.g. `Date.now()`
 spentTime, // null || millisecond difference
 leftTime // null || millisecond difference
}

instead of just progress value as it was before


UI flow:

  • show syncStartedAt and spentTime and leftTime only when sync is going on
  • if sync catches/throws an error while processing these values can be null. So if progress is not the number don't show the estimated time
  • if any variable from syncStartedAt, spentTime, leftTime is null then, for that variable, show Estimating... or something similar instead of just null

Copy link
Contributor

@ezewer ezewer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants