[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
This commit is contained in:
Mark Hahnenberg 2017-03-27 12:05:30 -07:00
parent 60e6113f87
commit 0508180712
2 changed files with 11 additions and 1 deletions

View file

@ -471,7 +471,11 @@ class FetchMessagesInFolderIMAP extends SyncTask {
if (savedSyncState.fetchedmin > savedSyncState.minUID) { if (savedSyncState.fetchedmin > savedSyncState.minUID) {
const lowerbound = Math.max(savedSyncState.minUID, savedSyncState.fetchedmin - batchSize); const lowerbound = Math.max(savedSyncState.minUID, savedSyncState.fetchedmin - batchSize);
// this._logger.log(`FetchMessagesInFolderIMAP: fetching ${lowerbound}:${savedSyncState.fetchedmin}`); // 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 { } else {
// this._logger.log("FetchMessagesInFolderIMAP: fetchedmin == minUID, nothing older to fetch.") // this._logger.log("FetchMessagesInFolderIMAP: fetchedmin == minUID, nothing older to fetch.")
} }

View file

@ -43,6 +43,7 @@ class SyncWorker {
this._lastSyncTime = null this._lastSyncTime = null
this._interrupted = false this._interrupted = false
this._syncInProgress = false this._syncInProgress = false
this._throttlingEnabled = false
this._stopped = false this._stopped = false
this._destroyed = false this._destroyed = false
this._shouldIgnoreInboxFlagUpdates = false this._shouldIgnoreInboxFlagUpdates = false
@ -82,6 +83,7 @@ class SyncWorker {
}) })
} }
if (seen === 500) { if (seen === 500) {
this._throttlingEnabled = true
MetricsReporter.reportEvent({ MetricsReporter.reportEvent({
nylasId, nylasId,
type: 'imap', type: 'imap',
@ -99,6 +101,10 @@ class SyncWorker {
} }
} }
throttlingEnabled() {
return this._throttlingEnabled;
}
_getInboxFolder() { _getInboxFolder() {
return this._db.Folder.find({where: {role: ['all', 'inbox']}}) return this._db.Folder.find({where: {role: ['all', 'inbox']}})
} }