Don't clear item as dirty if it was marked dirty after a sync began

This commit is contained in:
Mo Bitar
2018-04-18 17:10:43 -05:00
parent f73d860955
commit 4d2c61d07c
3 changed files with 27 additions and 1 deletions

View File

@@ -64,6 +64,16 @@ class Item {
setDirty(dirty) {
this.dirty = dirty;
// Allows the syncManager to check if an item has been marked dirty after a sync has been started
// This prevents it from clearing it as a dirty item after sync completion, if someone else has marked it dirty
// again after an ongoing sync.
if(!this.dirtyCount) { this.dirtyCount = 0; }
if(dirty) {
this.dirtyCount++;
} else {
this.dirtyCount = 0;
}
if(dirty) {
this.notifyObserversOfChange();
}

View File

@@ -270,6 +270,12 @@ class SyncManager {
return itemParams.paramsForSync();
}.bind(this));
for(var item of subItems) {
// Reset dirty counter to 0, since we're about to sync it.
// This means anyone marking the item as dirty after this will cause it so sync again and not be cleared on sync completion.
item.dirtyCount = 0;
}
params.sync_token = this.syncToken;
params.cursor_token = this.cursorToken;
@@ -278,7 +284,15 @@ class SyncManager {
}.bind(this);
var onSyncSuccess = function(response) {
this.modelManager.clearDirtyItems(subItems);
// Check to make sure any subItem hasn't been marked as dirty again while a sync was ongoing
var itemsToClearAsDirty = [];
for(var item of subItems) {
if(item.dirtyCount == 0) {
// Safe to clear as dirty
itemsToClearAsDirty.push(item);
}
}
this.modelManager.clearDirtyItems(itemsToClearAsDirty);
this.syncStatus.error = null;
this.$rootScope.$broadcast("sync:updated_token", this.syncToken);

View File

@@ -173,6 +173,8 @@
%input{"type" => "file", "style" => "display: none;", "file-change" => "->", "handler" => "importFileSelected(files)"}
.label Import From Backup
%span{"ng-if" => "isDesktopApplication()"} Backups are automatically created on desktop and can be managed via the "Backups" top-level menu.
%div{"ng-if" => "importData.requestPassword"}
%form.panel-form.stretch{"ng-submit" => "submitImportPassword()"}
%p Enter the account password associated with the import file.