From 050818071276a9c821a95315b1655a84c9d6a354 Mon Sep 17 00:00:00 2001 From: Mark Hahnenberg Date: Mon, 27 Mar 2017 12:05:30 -0700 Subject: [PATCH] [client-sync] Don't throttle while syncing first 500 threads Summary: We want to get to a usable inbox as quickly as possible, and throttling prevents this. We should basically only be throttling for historical mail syncing. Test Plan: Run initial sync benchmark, it's 117% faster on battery Reviewers: evan, juan, spang Reviewed By: juan, spang Differential Revision: https://phab.nylas.com/D4266 --- .../sync-tasks/fetch-messages-in-folder.imap.es6 | 6 +++++- packages/client-sync/src/local-sync-worker/sync-worker.es6 | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/client-sync/src/local-sync-worker/sync-tasks/fetch-messages-in-folder.imap.es6 b/packages/client-sync/src/local-sync-worker/sync-tasks/fetch-messages-in-folder.imap.es6 index 3f85df8e8..ef9dcf093 100644 --- a/packages/client-sync/src/local-sync-worker/sync-tasks/fetch-messages-in-folder.imap.es6 +++ b/packages/client-sync/src/local-sync-worker/sync-tasks/fetch-messages-in-folder.imap.es6 @@ -471,7 +471,11 @@ class FetchMessagesInFolderIMAP extends SyncTask { if (savedSyncState.fetchedmin > savedSyncState.minUID) { const lowerbound = Math.max(savedSyncState.minUID, savedSyncState.fetchedmin - batchSize); // this._logger.log(`FetchMessagesInFolderIMAP: fetching ${lowerbound}:${savedSyncState.fetchedmin}`); - totalProcessedMessages += yield this._fetchAndProcessMessages({min: lowerbound, max: savedSyncState.fetchedmin}); + totalProcessedMessages += yield this._fetchAndProcessMessages({ + min: lowerbound, + max: savedSyncState.fetchedmin, + throttle: this._syncWorker.throttlingEnabled(), + }); } else { // this._logger.log("FetchMessagesInFolderIMAP: fetchedmin == minUID, nothing older to fetch.") } diff --git a/packages/client-sync/src/local-sync-worker/sync-worker.es6 b/packages/client-sync/src/local-sync-worker/sync-worker.es6 index 7cda3968b..1a61c2264 100644 --- a/packages/client-sync/src/local-sync-worker/sync-worker.es6 +++ b/packages/client-sync/src/local-sync-worker/sync-worker.es6 @@ -43,6 +43,7 @@ class SyncWorker { this._lastSyncTime = null this._interrupted = false this._syncInProgress = false + this._throttlingEnabled = false this._stopped = false this._destroyed = false this._shouldIgnoreInboxFlagUpdates = false @@ -82,6 +83,7 @@ class SyncWorker { }) } if (seen === 500) { + this._throttlingEnabled = true MetricsReporter.reportEvent({ nylasId, type: 'imap', @@ -99,6 +101,10 @@ class SyncWorker { } } + throttlingEnabled() { + return this._throttlingEnabled; + } + _getInboxFolder() { return this._db.Folder.find({where: {role: ['all', 'inbox']}}) }