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.
This commit is contained in:
Dan Stillman 2021-04-22 03:27:01 -04:00
parent bb75fcd784
commit 57fbe61f93

View file

@ -18,6 +18,7 @@ var Zotero_Import_Mendeley = function () {
this._db; this._db;
this._file; this._file;
this._saveOptions = null;
this._itemDone; this._itemDone;
this._progress = 0; this._progress = 0;
this._progressMax; this._progressMax;
@ -50,6 +51,10 @@ Zotero_Import_Mendeley.prototype.setTranslator = function () {};
Zotero_Import_Mendeley.prototype.translate = async function (options = {}) { Zotero_Import_Mendeley.prototype.translate = async function (options = {}) {
this._linkFiles = options.linkFiles; this._linkFiles = options.linkFiles;
this._saveOptions = {
skipSelect: true,
...(options.saveOptions || {})
};
this.timestamp = Date.now(); this.timestamp = Date.now();
if (true) { if (true) {
@ -431,9 +436,7 @@ Zotero_Import_Mendeley.prototype._saveCollections = async function (libraryID, j
delete toSave.remoteUUID; delete toSave.remoteUUID;
collection.fromJSON(toSave); collection.fromJSON(toSave);
await collection.saveTx({ await collection.saveTx(this._saveOptions);
skipSelect: true
});
} }
}; };
@ -1249,8 +1252,8 @@ Zotero_Import_Mendeley.prototype._saveItems = async function (libraryID, json) {
item.fromJSON(toSave); item.fromJSON(toSave);
await item.saveTx({ await item.saveTx({
skipSelect: true, skipDateModifiedUpdate: true,
skipDateModifiedUpdate: true ...this._saveOptions
}); });
if (itemJSON.documentID) { if (itemJSON.documentID) {
idMap.set(itemJSON.documentID, item.id); idMap.set(itemJSON.documentID, item.id);
@ -1402,9 +1405,7 @@ Zotero_Import_Mendeley.prototype._saveFilesAndAnnotations = async function (file
attachment.setRelations({ attachment.setRelations({
'mendeleyDB:fileHash': file.hash 'mendeleyDB:fileHash': file.hash
}); });
await attachment.saveTx({ await attachment.saveTx(this._saveOptions);
skipSelect: true
});
} }
} }
else { else {
@ -1497,7 +1498,7 @@ Zotero_Import_Mendeley.prototype._saveAnnotations = async function (annotations,
let type = 'application/pdf'; let type = 'application/pdf';
if (Zotero.MIME.sniffForMIMEType(await Zotero.File.getSample(file)) == type) { if (Zotero.MIME.sniffForMIMEType(await Zotero.File.getSample(file)) == type) {
attachmentItem.attachmentContentType = 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('<h1>' + Zotero.getString('extractedAnnotations') + '</h1>\n' + noteStrings.join('\n')); note.setNote('<h1>' + Zotero.getString('extractedAnnotations') + '</h1>\n' + noteStrings.join('\n'));
return note.saveTx({ return note.saveTx(this._saveOptions);
skipSelect: true
});
}; };