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.
This commit is contained in:
parent
7ace5ea29e
commit
5eb6935842
1 changed files with 17 additions and 5 deletions
|
@ -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
|
// If an auto-sync was queued while a sync was ongoing, start again with its options
|
||||||
else if (_queuedSyncOptions.length) {
|
else if (_queuedSyncOptions.length) {
|
||||||
Zotero.debug("Restarting sync");
|
Zotero.debug("Restarting sync");
|
||||||
yield this._sync(_queuedSyncOptions.shift());
|
yield this._sync(JSON.parse(_queuedSyncOptions.shift()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -925,7 +925,7 @@ Zotero.Sync.Runner_Module = function (options = {}) {
|
||||||
/**
|
/**
|
||||||
* @param {Integer} timeout - Timeout in seconds
|
* @param {Integer} timeout - Timeout in seconds
|
||||||
* @param {Boolean} [recurring=false]
|
* @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 = {}) {
|
this.setSyncTimeout = function (timeout, recurring, options = {}) {
|
||||||
if (!Zotero.Prefs.get('sync.autoSync') || !this.enabled) {
|
if (!Zotero.Prefs.get('sync.autoSync') || !this.enabled) {
|
||||||
|
@ -968,13 +968,13 @@ Zotero.Sync.Runner_Module = function (options = {}) {
|
||||||
|
|
||||||
if (Zotero.locked) {
|
if (Zotero.locked) {
|
||||||
Zotero.debug('Zotero is locked -- skipping auto-sync', 4);
|
Zotero.debug('Zotero is locked -- skipping auto-sync', 4);
|
||||||
_queuedSyncOptions.push(mergedOpts);
|
_queueSyncOptions(mergedOpts);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_syncInProgress) {
|
if (_syncInProgress) {
|
||||||
Zotero.debug('Sync already in progress -- skipping auto-sync', 4);
|
Zotero.debug('Sync already in progress -- skipping auto-sync', 4);
|
||||||
_queuedSyncOptions.push(mergedOpts);
|
_queueSyncOptions(mergedOpts);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -996,7 +996,7 @@ Zotero.Sync.Runner_Module = function (options = {}) {
|
||||||
else {
|
else {
|
||||||
if (_syncInProgress) {
|
if (_syncInProgress) {
|
||||||
Zotero.debug('Sync in progress -- not setting auto-sync timeout', 4);
|
Zotero.debug('Sync in progress -- not setting auto-sync timeout', 4);
|
||||||
_queuedSyncOptions.push(mergedOpts);
|
_queueSyncOptions(mergedOpts);
|
||||||
return;
|
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 () {
|
this.clearSyncTimeout = function () {
|
||||||
if (_autoSyncTimer) {
|
if (_autoSyncTimer) {
|
||||||
_autoSyncTimer.cancel();
|
_autoSyncTimer.cancel();
|
||||||
|
|
Loading…
Reference in a new issue