Take a promise-returning function in Utilities.Internal.forEachChunkAsync()
Instead of a promise-yielding generator
This commit is contained in:
parent
4f55f28e7d
commit
9d0d79c9c2
4 changed files with 11 additions and 14 deletions
|
@ -460,7 +460,7 @@ Zotero.DataObjects.prototype.updateVersion = Zotero.Promise.method(function (ids
|
|||
return Zotero.Utilities.Internal.forEachChunkAsync(
|
||||
ids,
|
||||
Zotero.DB.MAX_BOUND_PARAMETERS,
|
||||
function* (chunk) {
|
||||
Zotero.Promise.coroutine(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++) {
|
||||
|
@ -470,7 +470,7 @@ Zotero.DataObjects.prototype.updateVersion = Zotero.Promise.method(function (ids
|
|||
obj.updateVersion(version, true);
|
||||
}
|
||||
}
|
||||
}.bind(this)
|
||||
}.bind(this))
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -487,7 +487,7 @@ Zotero.DataObjects.prototype.updateSynced = Zotero.Promise.method(function (ids,
|
|||
return Zotero.Utilities.Internal.forEachChunkAsync(
|
||||
ids,
|
||||
Zotero.DB.MAX_BOUND_PARAMETERS,
|
||||
function* (chunk) {
|
||||
Zotero.Promise.coroutine(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++) {
|
||||
|
@ -497,7 +497,7 @@ Zotero.DataObjects.prototype.updateSynced = Zotero.Promise.method(function (ids,
|
|||
obj.updateSynced(!!synced, true);
|
||||
}
|
||||
}
|
||||
}.bind(this)
|
||||
}.bind(this))
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -528,10 +528,10 @@ Zotero.Items = function() {
|
|||
|
||||
deletedIDs = yield this.getDeleted(libraryID, true, days);
|
||||
if (deletedIDs.length) {
|
||||
yield Zotero.Utilities.Internal.forEachChunkAsync(deletedIDs, 50, function* (chunk) {
|
||||
yield Zotero.Utilities.Internal.forEachChunkAsync(deletedIDs, 50, Zotero.Promise.coroutine(function* (chunk) {
|
||||
yield this.erase(chunk);
|
||||
yield Zotero.Notifier.trigger('refresh', 'trash', libraryID);
|
||||
}.bind(this));
|
||||
}.bind(this)));
|
||||
}
|
||||
|
||||
if (deletedIDs.length) {
|
||||
|
|
|
@ -191,7 +191,7 @@ Zotero.Tags = new function() {
|
|||
yield Zotero.Utilities.Internal.forEachChunkAsync(
|
||||
oldItemIDs,
|
||||
Zotero.DB.MAX_BOUND_PARAMETERS - 2,
|
||||
function* (chunk) {
|
||||
Zotero.Promise.coroutine(function* (chunk) {
|
||||
let placeholders = chunk.map(function () '?').join(',');
|
||||
|
||||
// This is ugly, but it's much faster than doing replaceTag() for each item
|
||||
|
@ -204,7 +204,7 @@ Zotero.Tags = new function() {
|
|||
yield Zotero.DB.queryAsync(sql, [Zotero.DB.transactionDateTime].concat(chunk));
|
||||
|
||||
yield Zotero.Items.reload(oldItemIDs, ['tags'], true);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
var notifierData = {};
|
||||
|
@ -292,7 +292,7 @@ Zotero.Tags = new function() {
|
|||
yield Zotero.Utilities.Internal.forEachChunkAsync(
|
||||
Zotero.Utilities.arrayUnique(oldItemIDs),
|
||||
Zotero.DB.MAX_BOUND_PARAMETERS - 1,
|
||||
function* (chunk) {
|
||||
Zotero.Promise.coroutine(function* (chunk) {
|
||||
let placeholders = chunk.map(function () '?').join(',');
|
||||
|
||||
sql = 'UPDATE items SET synced=0, clientDateModified=? '
|
||||
|
@ -300,7 +300,7 @@ Zotero.Tags = new function() {
|
|||
yield Zotero.DB.queryAsync(sql, [Zotero.DB.transactionDateTime].concat(chunk));
|
||||
|
||||
yield Zotero.Items.reload(oldItemIDs, ['primaryData', 'tags'], true);
|
||||
}
|
||||
})
|
||||
);
|
||||
}.bind(this));
|
||||
|
||||
|
|
|
@ -35,8 +35,7 @@ Zotero.Utilities.Internal = {
|
|||
*
|
||||
* @param {Array} arr
|
||||
* @param {Integer} chunkSize
|
||||
* @param {Function|GeneratorFunction} func - A promise-returning function or a
|
||||
* promise-yielding generator
|
||||
* @param {Function} func - A promise-returning function
|
||||
* @return {Array} The return values from the successive runs
|
||||
*/
|
||||
"forEachChunkAsync": Zotero.Promise.coroutine(function* (arr, chunkSize, func) {
|
||||
|
@ -45,8 +44,6 @@ 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;
|
||||
|
|
Loading…
Reference in a new issue