From 9579aa154af6418ad2df64b10bafa03301937ee1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adomas=20Ven=C4=8Dkauskas?= Date: Fri, 21 Mar 2025 09:55:53 +0200 Subject: [PATCH] Do not return recognizer promises early (#5148) --- chrome/content/zotero/xpcom/recognizeDocument.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/chrome/content/zotero/xpcom/recognizeDocument.js b/chrome/content/zotero/xpcom/recognizeDocument.js index 518ad61ebd..c6275fc847 100644 --- a/chrome/content/zotero/xpcom/recognizeDocument.js +++ b/chrome/content/zotero/xpcom/recognizeDocument.js @@ -58,8 +58,8 @@ Zotero.RecognizeDocument = new function () { async function _processQueue() { await Zotero.Schema.schemaUpdatePromise; - if (_queueProcessing) return; - _queueProcessing = true; + if (_queueProcessing) return _queueProcessing.promise; + _queueProcessing = Zotero.Promise.defer(); while (1) { // While all current progress queue usages are related with @@ -99,6 +99,7 @@ Zotero.RecognizeDocument = new function () { } } + _queueProcessing.resolve(); _queueProcessing = false; _processingItemID = null; } @@ -253,6 +254,7 @@ Zotero.RecognizeDocument = new function () { * @return {Promise} A promise that resolves to a newly created, recognized parent item */ async function _processItem(attachment) { + Zotero.debug(`RecognizeDocument: Recognizing attachment ${attachment.getDisplayTitle()}`); // Make sure the attachment still doesn't have a parent if (attachment.parentItemID) { throw new Error('Already has parent'); @@ -270,8 +272,10 @@ Zotero.RecognizeDocument = new function () { let parentItem = await Zotero.RecognizeDocument._recognize(attachment); if (!parentItem) { + Zotero.debug(`RecognizeDocument: No matches for attachment ${attachment.getDisplayTitle()}`); throw new Zotero.Exception.Alert("recognizePDF.noMatches"); } + Zotero.debug(`RecognizeDocument: Recognized attachment ${attachment.getDisplayTitle()}`); // Put new item in same collections as the old one let collections = attachment.getCollections();