From 4db311eb46df70402f8ef9f1fa4af29667871f69 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 4 Aug 2023 20:21:15 -0400 Subject: [PATCH] Serialize lookup requests These were switched to parallel in 86b77cc45, resulting in blocks: https://forums.zotero.org/discussion/106658/limited-amount-of-articles-that-can-be-added-through-pmid (cherry picked from commit fcc68d6d80d00097f1f34fc2bcf5d911d501a827) --- chrome/content/zotero/createParentDialog.js | 2 +- chrome/content/zotero/lookup.js | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/chrome/content/zotero/createParentDialog.js b/chrome/content/zotero/createParentDialog.js index 2253f7da05..47f6e47f93 100644 --- a/chrome/content/zotero/createParentDialog.js +++ b/chrome/content/zotero/createParentDialog.js @@ -68,7 +68,7 @@ async function doAccept() { ); // If we successfully created a parent, return it - if (newItems) { + if (newItems.length) { io.dataOut = { parent: newItems[0] }; window.close(); } diff --git a/chrome/content/zotero/lookup.js b/chrome/content/zotero/lookup.js index 60a563a1f1..02fb828935 100644 --- a/chrome/content/zotero/lookup.js +++ b/chrome/content/zotero/lookup.js @@ -40,7 +40,7 @@ var Zotero_Lookup = new function () { * @param textBox {HTMLElement} - Textbox containing identifiers * @param childItem {Zotero.Item|false} - Child item (optional) * @param toggleProgress {function} - Callback to toggle progress on/off - * @returns {Promise} + * @returns {Promise} */ this.addItemsFromIdentifier = async function (textBox, childItem, toggleProgress) { var identifiers = Zotero.Utilities.extractIdentifiers(textBox.value); @@ -79,11 +79,11 @@ var Zotero_Lookup = new function () { } } - let newItems = false; toggleProgress(true); - await Zotero.Promise.all(identifiers.map(async (identifier) => { - var translate = new Zotero.Translate.Search(); + let newItems = []; + for (let identifier of identifiers) { + let translate = new Zotero.Translate.Search(); translate.setIdentifier(identifier); // be lenient about translators @@ -91,20 +91,20 @@ var Zotero_Lookup = new function () { translate.setTranslator(translators); try { - newItems = await translate.translate({ + newItems.push(...await translate.translate({ libraryID, collections, saveAttachments: !childItem - }); + })); } // Continue with other ids on failure catch (e) { Zotero.logError(e); } - })); + } toggleProgress(false); - if (!newItems) { + if (!newItems.length) { Zotero.alert( window, Zotero.getString("lookup.failure.title"), @@ -126,7 +126,7 @@ var Zotero_Lookup = new function () { on => Zotero_Lookup.toggleProgress(on) ); - if (newItems) { + if (newItems.length) { document.getElementById("zotero-lookup-panel").hidePopup(); } return false;