Fix unnecessary sync looping after downloading items

An extra sync loop would be performed for every object downloaded, so a
download to an empty database could result in a huge number of
unnecessary loops. This was a regression from 52932b6eb, which started
queuing auto-syncs while a sync was in progress. The fix here is to skip
auto-sync for all objects saved from a sync download.

There are two new mechanisms involved:

- Event-level notifier options that get passed to passed to notify() at
  the top level of extraData rather than being included with every
  object (e.g., because `skipAutoSync` should apply to an entire save
  transaction)
- The ability to pass event-level notifier options when initializing
  a Zotero.Notifier.Queue, such as the one used for sync downloads
This commit is contained in:
Dan Stillman 2021-05-14 03:26:14 -04:00
parent 5b0f02a12b
commit 7ace5ea29e
6 changed files with 113 additions and 12 deletions

View file

@ -78,4 +78,38 @@ describe("Zotero.Notifier", function () {
assert.isTrue(promise2.isRejected());
});
});
describe("Queue", function () {
describe("#commit()", function () {
it("should add options from queue to extraData", async function () {
var called = false;
var data;
var notifierID = Zotero.Notifier.registerObserver({
notify: (event, type, ids, extraData) => {
called = true;
data = extraData;
}
});
var notifierQueue = new Zotero.Notifier.Queue({
skipAutoSync: true
});
var item = createUnsavedDataObject('item');
await item.saveTx({
notifierQueue
});
assert.isFalse(called);
await Zotero.Notifier.commit(notifierQueue);
assert.isTrue(called);
assert.propertyVal(data, 'skipAutoSync', true);
Zotero.Notifier.unregisterObserver(notifierID);
});
});
});
});