diff --git a/chrome/content/zotero/xpcom/data/dataObjects.js b/chrome/content/zotero/xpcom/data/dataObjects.js index 2dd1eae12b..edbfb5dc9b 100644 --- a/chrome/content/zotero/xpcom/data/dataObjects.js +++ b/chrome/content/zotero/xpcom/data/dataObjects.js @@ -448,7 +448,9 @@ Zotero.DataObjects.prototype.updateVersion = Zotero.Promise.method(function (ids let sql = "UPDATE " + this.table + " SET version=" + version + " " + "WHERE " + this.idColumn + " IN ("; return Zotero.Utilities.Internal.forEachChunkAsync( - ids, Zotero.DB.MAX_BOUND_PARAMETERS, Zotero.Promise.coroutine(function* (chunk) { + ids, + Zotero.DB.MAX_BOUND_PARAMETERS, + function* (chunk) { yield Zotero.DB.queryAsync(sql + chunk.map(() => '?').join(', ') + ')', chunk); // Update the internal 'version' property of any loaded objects for (let i = 0; i < chunk.length; i++) { @@ -458,7 +460,7 @@ Zotero.DataObjects.prototype.updateVersion = Zotero.Promise.method(function (ids obj.updateVersion(version, true); } } - }.bind(this)) + }.bind(this) ); }); @@ -473,7 +475,9 @@ Zotero.DataObjects.prototype.updateSynced = Zotero.Promise.method(function (ids, let sql = "UPDATE " + this.table + " SET synced=" + (synced ? 1 : 0) + " " + "WHERE " + this.idColumn + " IN ("; return Zotero.Utilities.Internal.forEachChunkAsync( - ids, Zotero.DB.MAX_BOUND_PARAMETERS, Zotero.Promise.coroutine(function* (chunk) { + ids, + Zotero.DB.MAX_BOUND_PARAMETERS, + function* (chunk) { yield Zotero.DB.queryAsync(sql + chunk.map(() => '?').join(', ') + ')', chunk); // Update the internal 'synced' property of any loaded objects for (let i = 0; i < chunk.length; i++) { @@ -483,7 +487,7 @@ Zotero.DataObjects.prototype.updateSynced = Zotero.Promise.method(function (ids, obj.updateSynced(!!synced, true); } } - }.bind(this)) + }.bind(this) ); }); diff --git a/chrome/content/zotero/xpcom/data/tags.js b/chrome/content/zotero/xpcom/data/tags.js index c500cd4c4a..31598722b4 100644 --- a/chrome/content/zotero/xpcom/data/tags.js +++ b/chrome/content/zotero/xpcom/data/tags.js @@ -252,7 +252,7 @@ Zotero.Tags = new function() { yield Zotero.Utilities.Internal.forEachChunkAsync( oldItemIDs, Zotero.DB.MAX_BOUND_PARAMETERS - 2, - Zotero.Promise.coroutine(function* (chunk) { + function* (chunk) { let placeholders = chunk.map(function () '?').join(','); // This is ugly, but it's much faster than doing replaceTag() for each item @@ -265,7 +265,7 @@ Zotero.Tags = new function() { yield Zotero.DB.queryAsync(sql, [Zotero.DB.transactionDateTime].concat(chunk)); yield Zotero.Items.reload(oldItemIDs, ['tags'], true); - }) + } ); var notifierData = {}; @@ -331,7 +331,7 @@ Zotero.Tags = new function() { yield Zotero.Utilities.Internal.forEachChunkAsync( Zotero.Utilities.arrayUnique(oldItemIDs), Zotero.DB.MAX_BOUND_PARAMETERS - 1, - Zotero.Promise.coroutine(function* (chunk) { + function* (chunk) { let placeholders = chunk.map(function () '?').join(','); sql = 'UPDATE items SET clientDateModified=? ' @@ -339,7 +339,7 @@ Zotero.Tags = new function() { yield Zotero.DB.queryAsync(sql, [Zotero.DB.transactionDateTime].concat(chunk)); yield Zotero.Items.reload(oldItemIDs, ['tags']); - }) + } ); }.bind(this)); diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js index 656057f375..5b57071fe4 100644 --- a/chrome/content/zotero/xpcom/utilities_internal.js +++ b/chrome/content/zotero/xpcom/utilities_internal.js @@ -35,7 +35,8 @@ Zotero.Utilities.Internal = { * * @param {Array} arr * @param {Integer} chunkSize - * @param {Function} func - A promise-returning function + * @param {Function|GeneratorFunction} func - A promise-returning function or a + * promise-yielding generator * @return {Array} The return values from the successive runs */ "forEachChunkAsync": Zotero.Promise.coroutine(function* (arr, chunkSize, func) { @@ -44,6 +45,8 @@ Zotero.Utilities.Internal = { var num = arr.length; var done = 0; + func = Zotero.Promise.coroutine(func); + do { var chunk = tmpArray.splice(0, chunkSize); done += chunk.length;