From f4ac511b50a3141c72a9d543fb396d1792ba15e2 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 14 Sep 2018 04:10:14 -0400 Subject: [PATCH] Copy items across libraries in batches of 100 This will hopefully fix failures when copying huge numbers of items. --- .../zotero/xpcom/collectionTreeView.js | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/chrome/content/zotero/xpcom/collectionTreeView.js b/chrome/content/zotero/xpcom/collectionTreeView.js index 887a769790..3728369bea 100644 --- a/chrome/content/zotero/xpcom/collectionTreeView.js +++ b/chrome/content/zotero/xpcom/collectionTreeView.js @@ -2169,16 +2169,22 @@ Zotero.CollectionTreeView.prototype.drop = Zotero.Promise.coroutine(function* (r if (!sameLibrary) { let toReconcile = []; - yield Zotero.DB.executeTransaction(function* () { - for (let item of newItems) { - var id = yield copyItem(item, targetLibraryID, copyOptions) - // Standalone attachments might not get copied - if (!id) { - continue; - } - newIDs.push(id); + yield Zotero.Utilities.Internal.forEachChunkAsync( + newItems, + 100, + function (chunk) { + return Zotero.DB.executeTransaction(async function () { + for (let item of chunk) { + var id = await copyItem(item, targetLibraryID, copyOptions) + // Standalone attachments might not get copied + if (!id) { + continue; + } + newIDs.push(id); + } + }); } - }); + ); if (toReconcile.length) { let sourceName = Zotero.Libraries.getName(items[0].libraryID);