mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-22 00:06:06 +08:00
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:
parent
72e206b4ab
commit
de60f0fde7
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue