fix(sync-state): Make sure folder progress goes between 0 and 1

Summary:
Also fix a related rendering issue and remove unused code.

Fixes T7538

Test Plan: tested locally

Reviewers: evan, spang, juan

Reviewed By: spang, juan

Maniphest Tasks: T7538

Differential Revision: https://phab.nylas.com/D3704
This commit is contained in:
Halla Moore 2017-01-15 19:19:16 -08:00
parent 72e206b4ab
commit de60f0fde7
2 changed files with 4 additions and 52 deletions

View file

@ -12,7 +12,6 @@ export default class InitialSyncActivity extends React.Component {
super(props);
this.state = {
syncState: NylasSyncStatusStore.getSyncState(),
syncProgress: NylasSyncStatusStore.getSyncProgress(),
}
this.mounted = false;
}
@ -33,9 +32,8 @@ export default class InitialSyncActivity extends React.Component {
}
onDataChanged = () => {
const syncState = NylasSyncStatusStore.getSyncState()
const syncProgress = NylasSyncStatusStore.getSyncProgress()
this.setState({syncState, syncProgress});
const syncState = Utils.deepClone(NylasSyncStatusStore.getSyncState())
this.setState({syncState});
}
renderFolderProgress(name, progress, oldestProcessedDate) {
@ -70,7 +68,7 @@ export default class InitialSyncActivity extends React.Component {
}
render() {
if (!AccountStore.accountsAreSyncing() || this.state.syncProgress.progress === 1) {
if (!AccountStore.accountsAreSyncing() || NylasSyncStatusStore.isSyncComplete()) {
return false;
}

View file

@ -99,7 +99,7 @@ class NylasSyncStatusStore extends NylasStore {
if (uidnext) {
// TODO: when we unify the databases, we shouldn't need code to
// calculate this in two different places anymore
const progress = (+minUID + (+fetchedmax - +fetchedmin) + 1) / uidnext
const progress = (+fetchedmax - +fetchedmin + 1) / (uidnext - minUID + 1)
updates[name] = {
progress,
total: uidnext,
@ -130,52 +130,6 @@ class NylasSyncStatusStore extends NylasStore {
return this._statesByAccount
}
/**
* Returns the weighted sync progress as a percentage, and
* the total number of messages to sync for a given account
*/
getSyncProgressForAccount(accountId) {
const state = this._statesByAccount[accountId]
if (!state) { return null }
const {folderSyncProgress} = this._statesByAccount[accountId]
if (!folderSyncProgress) { return null }
const folderNames = Object.keys(folderSyncProgress)
const progressPerFolder = folderNames.map(fname => folderSyncProgress[fname])
const weightedProgress = progressPerFolder.reduce(
(accum, {progress, total}) => accum + progress * total, 0
)
const totalMessageCount = progressPerFolder.reduce(
(accum, {total}) => accum + total, 0
)
return {
progress: weightedProgress / totalMessageCount,
total: totalMessageCount,
}
}
/**
* Returns the weighted sync progress for all accounts as a percentage, and
* the total number of messages to sync
*/
getSyncProgress() {
const accountIds = AccountStore.accountIds()
const progressPerAccount = (
accountIds
.map(accId => this.getSyncProgressForAccount(accId))
.filter(p => p != null)
)
const weightedProgress = progressPerAccount.reduce(
(accum, {progress, total}) => accum + progress * total, 0
)
const totalMessageCount = progressPerAccount.reduce(
(accum, {total}) => accum + total, 0
)
return {
progress: totalMessageCount ? weightedProgress / totalMessageCount : 0,
total: totalMessageCount,
}
}
/**
* Returns true if N1's local cache contains the entire list of available
* folders and labels.