From 117bc45ed4a8880e6332f28a759abfa3fa323a90 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Sat, 5 Aug 2023 00:01:39 -0400 Subject: [PATCH] Look up PubMed IDs in batches of 200 https://forums.zotero.org/discussion/comment/440245/#Comment_440245 (cherry picked from commit af91173734889f7a28870516d9ddaf4d15dc559d) --- chrome/content/zotero/lookup.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/chrome/content/zotero/lookup.js b/chrome/content/zotero/lookup.js index 02fb828935..6a1d1b90b4 100644 --- a/chrome/content/zotero/lookup.js +++ b/chrome/content/zotero/lookup.js @@ -81,6 +81,23 @@ var Zotero_Lookup = new function () { toggleProgress(true); + // Group PubMed IDs into batches of 200 + // + // Up to 10,000 ids can apparently be passed in a single request, but 200 is the recommended + // limit for GET, which we currently use, and passing batches of 200 seems...fine. + // + // https://www.ncbi.nlm.nih.gov/books/NBK25499/#chapter4.id + if (identifiers.length && identifiers[0].PMID) { + let chunkSize = 200; + let newIdentifiers = []; + for (let i = 0; i < identifiers.length; i += chunkSize) { + newIdentifiers.push({ + PMID: identifiers.slice(i, i + chunkSize).map(x => x.PMID) + }); + } + identifiers = newIdentifiers; + } + let newItems = []; for (let identifier of identifiers) { let translate = new Zotero.Translate.Search();