Only write sync timestamp after a complete sync

This commit is contained in:
Justin SB
2014-09-29 08:09:37 -07:00
parent e9a88b00b9
commit 2175da218b
2 changed files with 7 additions and 4 deletions

View File

@@ -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);
}
});
},

View File

@@ -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).