Mendeley import: Don't use single transaction

This commit is contained in:
Dan Stillman 2018-06-13 10:27:26 -04:00
parent 94a0c3ce8c
commit d38d55e2b4

View File

@ -806,52 +806,51 @@ Zotero_Import_Mendeley.prototype._convertNote = function (note) {
Zotero_Import_Mendeley.prototype._saveItems = async function (libraryID, json) { Zotero_Import_Mendeley.prototype._saveItems = async function (libraryID, json) {
var idMap = new Map(); var idMap = new Map();
await Zotero.DB.executeTransaction(async function () {
var lastExistingParentItem;
for (let i = 0; i < json.length; i++) {
let itemJSON = json[i];
// Check if the item has been previously imported var lastExistingParentItem;
let item = this._findExistingItem(libraryID, itemJSON, lastExistingParentItem); for (let i = 0; i < json.length; i++) {
if (item) { let itemJSON = json[i];
if (item.isRegularItem()) {
lastExistingParentItem = item;
// Update any child items to point to the existing item's key instead of the // Check if the item has been previously imported
// new generated one let item = this._findExistingItem(libraryID, itemJSON, lastExistingParentItem);
this._updateParentKeys('item', json, i + 1, itemJSON.key, item.key); if (item) {
if (item.isRegularItem()) {
lastExistingParentItem = item;
// Leave item in any collections it's in // Update any child items to point to the existing item's key instead of the
itemJSON.collections = item.getCollections() // new generated one
.map(id => Zotero.Collections.getLibraryAndKeyFromID(id).key) this._updateParentKeys('item', json, i + 1, itemJSON.key, item.key);
.concat(itemJSON.collections || []);
}
}
else {
lastExistingParentItem = null;
item = new Zotero.Item; // Leave item in any collections it's in
item.libraryID = libraryID; itemJSON.collections = item.getCollections()
if (itemJSON.key) { .map(id => Zotero.Collections.getLibraryAndKeyFromID(id).key)
item.key = itemJSON.key; .concat(itemJSON.collections || []);
await item.loadPrimaryData();
}
}
// Remove external id before save
let toSave = Object.assign({}, itemJSON);
delete toSave.documentID;
item.fromJSON(toSave);
await item.save({
skipSelect: true,
skipDateModifiedUpdate: true
});
if (itemJSON.documentID) {
idMap.set(itemJSON.documentID, item.id);
} }
} }
}.bind(this)); else {
lastExistingParentItem = null;
item = new Zotero.Item;
item.libraryID = libraryID;
if (itemJSON.key) {
item.key = itemJSON.key;
await item.loadPrimaryData();
}
}
// Remove external id before save
let toSave = Object.assign({}, itemJSON);
delete toSave.documentID;
item.fromJSON(toSave);
await item.saveTx({
skipSelect: true,
skipDateModifiedUpdate: true
});
if (itemJSON.documentID) {
idMap.set(itemJSON.documentID, item.id);
}
}
return idMap; return idMap;
}; };