From 57fbe61f936f1d0efd8ff9be288077b3cd0d8b03 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Thu, 22 Apr 2021 03:27:01 -0400 Subject: [PATCH] Use notifier queue during Mendeley import This dramatically speeds up Mendeley imports by avoiding UI updates. Regular imports in fileInterface have done this for a while, but the Mendeley importer used a fake translation object that didn't use the passed queue. After this change, a 10,000-item import goes from 9m30s to 2m45s, a 71% decrease. --- .../zotero/import/mendeley/mendeleyImport.js | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/chrome/content/zotero/import/mendeley/mendeleyImport.js b/chrome/content/zotero/import/mendeley/mendeleyImport.js index 3a8d7704c4..a999c516ef 100644 --- a/chrome/content/zotero/import/mendeley/mendeleyImport.js +++ b/chrome/content/zotero/import/mendeley/mendeleyImport.js @@ -18,6 +18,7 @@ var Zotero_Import_Mendeley = function () { this._db; this._file; + this._saveOptions = null; this._itemDone; this._progress = 0; this._progressMax; @@ -50,6 +51,10 @@ Zotero_Import_Mendeley.prototype.setTranslator = function () {}; Zotero_Import_Mendeley.prototype.translate = async function (options = {}) { this._linkFiles = options.linkFiles; + this._saveOptions = { + skipSelect: true, + ...(options.saveOptions || {}) + }; this.timestamp = Date.now(); if (true) { @@ -431,9 +436,7 @@ Zotero_Import_Mendeley.prototype._saveCollections = async function (libraryID, j delete toSave.remoteUUID; collection.fromJSON(toSave); - await collection.saveTx({ - skipSelect: true - }); + await collection.saveTx(this._saveOptions); } }; @@ -1249,8 +1252,8 @@ Zotero_Import_Mendeley.prototype._saveItems = async function (libraryID, json) { item.fromJSON(toSave); await item.saveTx({ - skipSelect: true, - skipDateModifiedUpdate: true + skipDateModifiedUpdate: true, + ...this._saveOptions }); if (itemJSON.documentID) { idMap.set(itemJSON.documentID, item.id); @@ -1402,9 +1405,7 @@ Zotero_Import_Mendeley.prototype._saveFilesAndAnnotations = async function (file attachment.setRelations({ 'mendeleyDB:fileHash': file.hash }); - await attachment.saveTx({ - skipSelect: true - }); + await attachment.saveTx(this._saveOptions); } } else { @@ -1497,7 +1498,7 @@ Zotero_Import_Mendeley.prototype._saveAnnotations = async function (annotations, let type = 'application/pdf'; if (Zotero.MIME.sniffForMIMEType(await Zotero.File.getSample(file)) == type) { attachmentItem.attachmentContentType = type; - await attachmentItem.saveTx(); + await attachmentItem.saveTx(this._saveOptions); } } @@ -1596,9 +1597,7 @@ Zotero_Import_Mendeley.prototype._saveAnnotations = async function (annotations, }); } note.setNote('

' + Zotero.getString('extractedAnnotations') + '

\n' + noteStrings.join('\n')); - return note.saveTx({ - skipSelect: true - }); + return note.saveTx(this._saveOptions); };