From b7cd644a83b45a621da4e64605e5d293ad67d63b Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Tue, 21 Jun 2016 17:51:24 -0700 Subject: [PATCH] More quietly update category sync state --- sync/imap/sync-mailbox-operation.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/sync/imap/sync-mailbox-operation.js b/sync/imap/sync-mailbox-operation.js index e1d25a463..e86a4d713 100644 --- a/sync/imap/sync-mailbox-operation.js +++ b/sync/imap/sync-mailbox-operation.js @@ -1,3 +1,4 @@ +const _ = require('underscore'); const {processMessage} = require(`${__base}/message-processor`); const {Capabilities} = require('./connection.js'); @@ -168,12 +169,11 @@ class SyncMailboxOperation { return this._imap.fetch(range, this._processMessage.bind(this)).then(() => { console.log(` - finished fetching unseen messages`); - this._category.syncState = Object.assign(this._category.syncState, { + return this.updateCategorySyncState({ uidnext: boxSyncState.uidnext, uidvalidity: boxSyncState.uidvalidity, timeFetchedUnseen: Date.now(), }); - return this._category.save(); }); } @@ -200,12 +200,11 @@ class SyncMailboxOperation { deletes: this._removeDeletedMessages(remoteUIDAttributes, localMessageAttributes), }) ).then(() => { - this._category.syncState = Object.assign(this._category.syncState, { + return this.updateCategorySyncState({ highestmodseq: nextHighestmodseq, timeDeepScan: Date.now(), timeShallowScan: Date.now(), }); - return this._category.save(); }) ); } @@ -229,15 +228,22 @@ class SyncMailboxOperation { }).then((localMessageAttributes) => this._createAndUpdateMessages(remoteUIDAttributes, localMessageAttributes) ).then(() => { - this._category.syncState = Object.assign(this._category.syncState, { + return this.updateCategorySyncState({ highestmodseq: nextHighestmodseq, timeShallowScan: Date.now(), }); - return this._category.save(); }) ) } + updateCategorySyncState(newState) { + if (_.isMatch(this._category.syncState, newState)) { + return Promise.resolve(); + } + this._category.syncState = Object.assign(this._category.syncState, newState); + return this._category.save(); + } + run(db, imap) { this._db = db; this._imap = imap;