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 fcc68d6d80)
This commit is contained in:
Dan Stillman 2023-08-04 20:21:15 -04:00
parent fb148497ba
commit 4db311eb46
2 changed files with 10 additions and 10 deletions

View file

@ -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();
}

View file

@ -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<boolean>}
* @returns {Promise<Zotero.Item[]>}
*/
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;