From 2175da218bd695b0b185d018f54ca121a5fc59a0 Mon Sep 17 00:00:00 2001 From: Justin SB Date: Mon, 29 Sep 2014 08:09:37 -0700 Subject: [PATCH] Only write sync timestamp after a complete sync --- tools/catalog-remote.js | 8 +++++--- tools/package-client.js | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/catalog-remote.js b/tools/catalog-remote.js index ea4142ab2b..d4571381ac 100644 --- a/tools/catalog-remote.js +++ b/tools/catalog-remote.js @@ -585,7 +585,7 @@ _.extend(RemoteCatalog.prototype, { }, //Given data from troposphere, add it into the local store - insertData: function(serverData) { + insertData: function(serverData, syncComplete) { var self = this; return self.db.runInTransaction(function (txn) { self.tablePackages.upsert(txn, serverData.collections.packages); @@ -599,8 +599,10 @@ _.extend(RemoteCatalog.prototype, { syncToken._id = "1"; //Add fake _id so it fits the pattern self.tableSyncToken.upsert(txn, [syncToken]); - var lastSync = { timestamp: Date.now() }; - self._setMetadata(txn, METADATA_LAST_SYNC, lastSync); + if (syncComplete) { + var lastSync = {timestamp: Date.now()}; + self._setMetadata(txn, METADATA_LAST_SYNC, lastSync); + } }); }, diff --git a/tools/package-client.js b/tools/package-client.js index b752576a75..eccae13a5d 100644 --- a/tools/package-client.js +++ b/tools/package-client.js @@ -221,7 +221,8 @@ _updateServerPackageData = function (dataStore, options) { // We always write to the data store; the fact there is no data is itself data! // e.g. the last-refresh timestamp - dataStore.insertData(remoteData); + var syncComplete = _.isEqual(remoteData.collections, {}) || remoteData.upToDate; + dataStore.insertData(remoteData, syncComplete); // If there is no new data from the server, don't bother writing things to // disk (unless we were just told to reset everything).