Fix SQL error saving an item with hundreds of related items

Fixes #2139
This commit is contained in:
Dan Stillman 2021-09-01 06:19:56 -04:00
parent 14b7206276
commit 576b9b7817

View file

@ -1102,10 +1102,16 @@ Zotero.DataObject.prototype._finalizeSave = Zotero.Promise.coroutine(function* (
toAdd[i][0] = yield Zotero.RelationPredicates.add(toAdd[i][0]);
env.relationsToRegister.push([toAdd[i][0], toAdd[i][1]]);
}
yield Zotero.DB.queryAsync(
sql + toAdd.map(x => "(?, ?, ?)").join(", "),
toAdd.map(x => [this.id, x[0], x[1]])
.reduce((x, y) => x.concat(y))
yield Zotero.Utilities.Internal.forEachChunkAsync(
toAdd,
Math.floor(Zotero.DB.MAX_BOUND_PARAMETERS / 3),
async function (chunk) {
await Zotero.DB.queryAsync(
sql + chunk.map(x => "(?, ?, ?)").join(", "),
chunk.map(x => [this.id, x[0], x[1]])
.reduce((x, y) => x.concat(y))
);
}.bind(this)
);
}