Mendeley import: Don't use single transaction
This commit is contained in:
parent
94a0c3ce8c
commit
d38d55e2b4
1 changed files with 42 additions and 43 deletions
|
@ -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;
|
var lastExistingParentItem;
|
||||||
for (let i = 0; i < json.length; i++) {
|
for (let i = 0; i < json.length; i++) {
|
||||||
let itemJSON = json[i];
|
let itemJSON = json[i];
|
||||||
|
|
||||||
// Check if the item has been previously imported
|
// Check if the item has been previously imported
|
||||||
let item = this._findExistingItem(libraryID, itemJSON, lastExistingParentItem);
|
let item = this._findExistingItem(libraryID, itemJSON, lastExistingParentItem);
|
||||||
if (item) {
|
if (item) {
|
||||||
if (item.isRegularItem()) {
|
if (item.isRegularItem()) {
|
||||||
lastExistingParentItem = item;
|
lastExistingParentItem = item;
|
||||||
|
|
||||||
// Update any child items to point to the existing item's key instead of the
|
|
||||||
// new generated one
|
|
||||||
this._updateParentKeys('item', json, i + 1, itemJSON.key, item.key);
|
|
||||||
|
|
||||||
// Leave item in any collections it's in
|
|
||||||
itemJSON.collections = item.getCollections()
|
|
||||||
.map(id => Zotero.Collections.getLibraryAndKeyFromID(id).key)
|
|
||||||
.concat(itemJSON.collections || []);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
lastExistingParentItem = null;
|
|
||||||
|
|
||||||
item = new Zotero.Item;
|
// Update any child items to point to the existing item's key instead of the
|
||||||
item.libraryID = libraryID;
|
// new generated one
|
||||||
if (itemJSON.key) {
|
this._updateParentKeys('item', json, i + 1, itemJSON.key, item.key);
|
||||||
item.key = itemJSON.key;
|
|
||||||
await item.loadPrimaryData();
|
// Leave item in any collections it's in
|
||||||
}
|
itemJSON.collections = item.getCollections()
|
||||||
}
|
.map(id => Zotero.Collections.getLibraryAndKeyFromID(id).key)
|
||||||
|
.concat(itemJSON.collections || []);
|
||||||
// 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;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue