From 5eb693584261f7d054e104366a7f55b18c586a0b Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 14 May 2021 03:16:44 -0400 Subject: [PATCH] Deduplicate queued sync options E.g., if a sync is ongoing and there are multiple item saves that would trigger auto-sync with the same options, only queue a single sync. 7ace5ea29e fixed the main cause of this, but in case some other saves end up happening during a sync, this will prevent them from triggering multiple sync loops with the same options. --- .../content/zotero/xpcom/sync/syncRunner.js | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/chrome/content/zotero/xpcom/sync/syncRunner.js b/chrome/content/zotero/xpcom/sync/syncRunner.js index 80b5ccda0e..cb12776127 100644 --- a/chrome/content/zotero/xpcom/sync/syncRunner.js +++ b/chrome/content/zotero/xpcom/sync/syncRunner.js @@ -337,7 +337,7 @@ Zotero.Sync.Runner_Module = function (options = {}) { // If an auto-sync was queued while a sync was ongoing, start again with its options else if (_queuedSyncOptions.length) { Zotero.debug("Restarting sync"); - yield this._sync(_queuedSyncOptions.shift()); + yield this._sync(JSON.parse(_queuedSyncOptions.shift())); return; } @@ -925,7 +925,7 @@ Zotero.Sync.Runner_Module = function (options = {}) { /** * @param {Integer} timeout - Timeout in seconds * @param {Boolean} [recurring=false] - * @param {Object} [options] - Sync options + * @param {Object} [options] - Sync options (e.g., 'libraries', 'fileLibraries', 'fullTextLibraries') */ this.setSyncTimeout = function (timeout, recurring, options = {}) { if (!Zotero.Prefs.get('sync.autoSync') || !this.enabled) { @@ -968,13 +968,13 @@ Zotero.Sync.Runner_Module = function (options = {}) { if (Zotero.locked) { Zotero.debug('Zotero is locked -- skipping auto-sync', 4); - _queuedSyncOptions.push(mergedOpts); + _queueSyncOptions(mergedOpts); return; } if (_syncInProgress) { Zotero.debug('Sync already in progress -- skipping auto-sync', 4); - _queuedSyncOptions.push(mergedOpts); + _queueSyncOptions(mergedOpts); return; } @@ -996,7 +996,7 @@ Zotero.Sync.Runner_Module = function (options = {}) { else { if (_syncInProgress) { Zotero.debug('Sync in progress -- not setting auto-sync timeout', 4); - _queuedSyncOptions.push(mergedOpts); + _queueSyncOptions(mergedOpts); return; } @@ -1008,6 +1008,18 @@ Zotero.Sync.Runner_Module = function (options = {}) { } + function _queueSyncOptions(options) { + var jsonOptions = JSON.stringify(options); + // Don't queue options if already queued + if (_queuedSyncOptions.includes(jsonOptions)) { + return; + } + Zotero.debug("Queueing sync options"); + Zotero.debug(options); + _queuedSyncOptions.push(jsonOptions); + } + + this.clearSyncTimeout = function () { if (_autoSyncTimer) { _autoSyncTimer.cancel();