[local-sync] Don't sync spam until everything else is synced

Summary: Addresses T7426

Test Plan: manual

Reviewers: evan, spang

Reviewed By: spang

Differential Revision: https://phab.nylas.com/D3655
This commit is contained in:
Juan Tejada 2017-01-12 13:42:57 -08:00
parent 59b5961a6c
commit 238b79d06c

View file

@ -346,10 +346,15 @@ class SyncWorker {
async _getFoldersToSync() { async _getFoldersToSync() {
const {Folder} = this._db; const {Folder} = this._db;
// Don't sync spam until everything else has been synced
const allFolders = await Folder.findAll();
const foldersExceptSpam = allFolders.filter((f) => f.role !== 'spam')
const shouldIncludeSpam = foldersExceptSpam.every((f) => f.isSyncComplete())
const foldersToSync = shouldIncludeSpam ? allFolders : foldersExceptSpam;
// TODO make sure this order is correct/ unit tests!! // TODO make sure this order is correct/ unit tests!!
const folders = await Folder.findAll(); const priority = ['inbox', 'all', 'sent', 'drafts', 'trash', 'spam'].reverse();
const priority = ['inbox', 'all', 'drafts', 'sent', 'trash', 'spam'].reverse(); return foldersToSync.sort((a, b) =>
return folders.sort((a, b) =>
(priority.indexOf(a.role) - priority.indexOf(b.role)) * -1 (priority.indexOf(a.role) - priority.indexOf(b.role)) * -1
) )
} }
@ -424,12 +429,6 @@ class SyncWorker {
const interval = shouldSyncImmediately ? 1 : intervals.active; const interval = shouldSyncImmediately ? 1 : intervals.active;
const nextSyncIn = Math.max(1, this._lastSyncTime + interval - Date.now()) const nextSyncIn = Math.max(1, this._lastSyncTime + interval - Date.now())
// this._logger.info({
// moreToSync,
// shouldSyncImmediately,
// interrupted: this._interrupted,
// nextSyncStartingIn: `${nextSyncIn}ms`,
// }, `SyncWorker: Scheduling next sync iteration`)
console.log(`🔃 🔜 in ${nextSyncIn}ms`) console.log(`🔃 🔜 in ${nextSyncIn}ms`)
this._syncTimer = setTimeout(() => { this._syncTimer = setTimeout(() => {