SyncManager exclude savedItems from retrievedItems, syncing source string
This commit is contained in:
@@ -189,7 +189,17 @@ class SyncManager {
|
||||
this.$interval.cancel(this.syncStatus.checker);
|
||||
}
|
||||
|
||||
sync(callback, options = {}) {
|
||||
sync(callback, options = {}, source) {
|
||||
|
||||
if(!options) options = {};
|
||||
|
||||
if(typeof callback == 'string') {
|
||||
// is source string, used to avoid filling parameters on call
|
||||
source = callback;
|
||||
callback = null;
|
||||
}
|
||||
|
||||
// console.log("Syncing from", source);
|
||||
|
||||
var allDirtyItems = this.modelManager.getDirtyItems();
|
||||
|
||||
@@ -271,6 +281,15 @@ class SyncManager {
|
||||
|
||||
this.$rootScope.$broadcast("sync:updated_token", this.syncToken);
|
||||
|
||||
// Filter retrieved_items to remove any items that may be in saved_items for this complete sync operation
|
||||
// When signing in, and a user requires many round trips to complete entire retrieval of data, an item may be saved
|
||||
// on the first trip, then on subsequent trips using cursor_token, this same item may be returned, since it's date is
|
||||
// greater than cursor_token. We keep track of all saved items in whole sync operation with this.allSavedItems
|
||||
// We need this because singletonManager looks at retrievedItems as higher precendence than savedItems, but if it comes in both
|
||||
// then that's problematic.
|
||||
let allSavedUUIDs = this.allSavedItems.map((item) => {return item.uuid});
|
||||
response.retrieved_items = response.retrieved_items.filter((candidate) => {return !allSavedUUIDs.includes(candidate.uuid)});
|
||||
|
||||
// Map retrieved items to local data
|
||||
var retrieved
|
||||
= this.handleItemsResponse(response.retrieved_items, null, ModelManager.MappingSourceRemoteRetrieved);
|
||||
@@ -307,12 +326,12 @@ class SyncManager {
|
||||
|
||||
if(this.cursorToken || this.syncStatus.needsMoreSync) {
|
||||
setTimeout(function () {
|
||||
this.sync(callback, options);
|
||||
this.sync(callback, options, "onSyncSuccess cursorToken || needsMoreSync");
|
||||
}.bind(this), 10); // wait 10ms to allow UI to update
|
||||
} else if(this.repeatOnCompletion) {
|
||||
this.repeatOnCompletion = false;
|
||||
setTimeout(function () {
|
||||
this.sync(callback, options);
|
||||
this.sync(callback, options, "onSyncSuccess repeatOnCompletion");
|
||||
}.bind(this), 10); // wait 10ms to allow UI to update
|
||||
} else {
|
||||
this.writeItemsToLocalStorage(this.allRetreivedItems, false, null);
|
||||
|
||||
Reference in New Issue
Block a user