From 878735f52ef5d96dfbc83debfb0eec3e0f18c850 Mon Sep 17 00:00:00 2001 From: Juan Tejada Date: Wed, 7 Dec 2016 16:16:45 -0800 Subject: [PATCH] [local-sync] Add todos --- .../local-sync-worker/imap/fetch-messages-in-folder.js | 4 ++++ packages/local-sync/src/local-sync-worker/sync-worker.js | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/packages/local-sync/src/local-sync-worker/imap/fetch-messages-in-folder.js b/packages/local-sync/src/local-sync-worker/imap/fetch-messages-in-folder.js index 256e71b03..839367fe2 100644 --- a/packages/local-sync/src/local-sync-worker/imap/fetch-messages-in-folder.js +++ b/packages/local-sync/src/local-sync-worker/imap/fetch-messages-in-folder.js @@ -259,6 +259,9 @@ class FetchMessagesInFolder { uid: existingMessage.folderImapUID, }, `FetchMessagesInFolder: Updated message`) } else { + // TODO investigate batching processing new messages + // We could measure load of actual sync vs load of just message processing + // to determine how meaningful it is processNewMessage(messageValues, imapMessage) this._logger.info({ message: messageValues, @@ -323,6 +326,7 @@ class FetchMessagesInFolder { } else { this._logger.info('FetchMessagesInFolder: fetchedmax == uidnext, nothing more recent to fetch.') } + if (savedSyncState.fetchedmin > 1) { const lowerbound = Math.max(1, savedSyncState.fetchedmin - FETCH_MESSAGES_COUNT); desiredRanges.push({min: lowerbound, max: savedSyncState.fetchedmin}) diff --git a/packages/local-sync/src/local-sync-worker/sync-worker.js b/packages/local-sync/src/local-sync-worker/sync-worker.js index c70fce3ad..d36900023 100644 --- a/packages/local-sync/src/local-sync-worker/sync-worker.js +++ b/packages/local-sync/src/local-sync-worker/sync-worker.js @@ -30,6 +30,7 @@ class SyncWorker { // the database, because otherwise things get /crazy/ messy and I don't like // having counters and garbage everywhere. if (!account.firstSyncCompletion) { + // TODO extract this into its own module, can use later on for exchange this._logger.info("This is initial sync. Setting up metrics collection!"); let seen = 0; @@ -188,6 +189,13 @@ class SyncWorker { } async syncMessagesInAllFolders() { + // TODO prioritize syncing all of inbox first if there's a ton of folders (e.g. imap + // accounts). If there are many folders, we would only sync the first n + // messages in the inbox and not go back to it until we've done the same for + // the rest of the folders, which would give the appearance of the inbox + // syncing slowly. This should only be done during initial sync. + // TODO Also consider using multiple imap connections, 1 for inbox, one for the + // rest const {Folder} = this._db; const {folderSyncOptions} = this._account.syncPolicy; @@ -196,6 +204,7 @@ class SyncWorker { const foldersSorted = folders.sort((a, b) => (priority.indexOf(a.role) - priority.indexOf(b.role)) * -1 ) + // TODO make sure this order is correct return await Promise.all(foldersSorted.map((cat) => this._conn.runOperation(new FetchMessagesInFolder(cat, folderSyncOptions, this._logger))