Fix format of object data added back to upload queue after failure

This commit is contained in:
Dan Stillman 2017-02-16 17:59:30 -05:00
parent ddb7d3107d
commit cbed716424

View File

@ -1000,7 +1000,7 @@ Zotero.Sync.Data.Engine.prototype._uploadObjects = Zotero.Promise.coroutine(func
} }
); );
} }
batch.push(o.json); batch.push(o);
} }
// No more non-failed requests // No more non-failed requests
@ -1011,8 +1011,10 @@ Zotero.Sync.Data.Engine.prototype._uploadObjects = Zotero.Promise.coroutine(func
// Remove selected and skipped objects from queue // Remove selected and skipped objects from queue
queue.splice(0, batch.length + numSkipped); queue.splice(0, batch.length + numSkipped);
let jsonBatch = batch.map(o => o.json);
Zotero.debug("UPLOAD BATCH:"); Zotero.debug("UPLOAD BATCH:");
Zotero.debug(batch); Zotero.debug(jsonBatch);
let results; let results;
let numSuccessful = 0; let numSuccessful = 0;
@ -1022,7 +1024,7 @@ Zotero.Sync.Data.Engine.prototype._uploadObjects = Zotero.Promise.coroutine(func
"POST", "POST",
libraryVersion, libraryVersion,
objectType, objectType,
batch jsonBatch
)); ));
// Mark successful and unchanged objects as synced with new version, // Mark successful and unchanged objects as synced with new version,
@ -1038,8 +1040,8 @@ Zotero.Sync.Data.Engine.prototype._uploadObjects = Zotero.Promise.coroutine(func
let key = state == 'successful' ? current.key : current; let key = state == 'successful' ? current.key : current;
let changed = changedObjects.has(key); let changed = changedObjects.has(key);
if (key != batch[index].key) { if (key != jsonBatch[index].key) {
throw new Error("Key mismatch (" + key + " != " + batch[index].key + ")"); throw new Error("Key mismatch (" + key + " != " + jsonBatch[index].key + ")");
} }
let obj = objectsClass.getByLibraryAndKey(this.libraryID, key); let obj = objectsClass.getByLibraryAndKey(this.libraryID, key);
@ -1070,13 +1072,14 @@ Zotero.Sync.Data.Engine.prototype._uploadObjects = Zotero.Promise.coroutine(func
// will guarantee that the item won't be redownloaded unnecessarily in the case of // will guarantee that the item won't be redownloaded unnecessarily in the case of
// a full sync, because the version will be higher than whatever version is on the // a full sync, because the version will be higher than whatever version is on the
// server. // server.
batch[index].version = libraryVersion; jsonBatch[index].version = libraryVersion;
toCache.push(batch[index]); toCache.push(jsonBatch[index]);
} }
numSuccessful++; numSuccessful++;
// Remove from batch to mark as successful // Remove from batch to mark as successful
delete batch[index]; delete batch[index];
delete jsonBatch[index];
} }
} }
yield Zotero.Sync.Data.Local.saveCacheObjects( yield Zotero.Sync.Data.Local.saveCacheObjects(
@ -1107,7 +1110,7 @@ Zotero.Sync.Data.Engine.prototype._uploadObjects = Zotero.Promise.coroutine(func
if (data) { if (data) {
e.data = data; e.data = data;
} }
Zotero.logError("Error for " + objectType + " " + batch[index].key + " in " Zotero.logError("Error for " + objectType + " " + jsonBatch[index].key + " in "
+ this.library.name + ":\n\n" + e); + this.library.name + ":\n\n" + e);
// This shouldn't happen, because the upload request includes a library version and should // This shouldn't happen, because the upload request includes a library version and should