Skip to content

Commit

Permalink
Use getAsync() to acquire subject in Zotero.Relations.getByObject()
Browse files Browse the repository at this point in the history
  • Loading branch information
fbennett committed Apr 9, 2018
1 parent bbc5206 commit 96c3b27
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions chrome/content/zotero/xpcom/data/relations.js
Expand Up @@ -146,7 +146,7 @@ Zotero.Relations = new function () {
* @return {Object[]} - An array of objects with a Zotero.DataObject as 'subject'
* and a predicate string as 'predicate'
*/
this.getByObject = function (objectType, object) {
this.getByObject = Zotero.Promise.coroutine(function* (objectType, object) {
var objectsClass = Zotero.DataObjectUtilities.getObjectsClassForObjectType(objectType);
var predicateIDs = [];
var o = _subjectPredicatesByObject[objectType]
Expand All @@ -156,13 +156,16 @@ Zotero.Relations = new function () {
}
var toReturn = [];
for (let predicateID in o) {
o[predicateID].forEach(subjectID => toReturn.push({
subject: objectsClass.get(subjectID),
predicate: Zotero.RelationPredicates.getName(predicateID)
}));
for (let subjectID of o[predicateID]) {
var subject = yield objectsClass.getAsync(subjectID);
toReturn.push({
subject: subject,
predicate: Zotero.RelationPredicates.getName(predicateID)
});
};
}
return toReturn;
};
});


this.updateUser = Zotero.Promise.coroutine(function* (fromUserID, toUserID) {
Expand All @@ -179,9 +182,9 @@ Zotero.Relations = new function () {
let objects = yield Zotero.DB.columnQueryAsync(
sql, 'http://zotero.org/users/' + fromUserID + '/%'
);
Zotero.DB.addCurrentCallback("commit", function () {
Zotero.DB.addCurrentCallback("commit", function* () {
for (let object of objects) {
let subPrefs = this.getByObject(type, object);
let subPrefs = yield this.getByObject(type, object);
let newObject = object.replace(
new RegExp("^http://zotero.org/users/" + fromUserID + "/(.*)"),
"http://zotero.org/users/" + toUserID + "/$1"
Expand Down Expand Up @@ -265,4 +268,4 @@ Zotero.Relations = new function () {
}
throw ("Invalid namespace in URI '" + uri + "' in Zotero.Relations._getPrefixAndValue()");
}
}
}

0 comments on commit 96c3b27

Please sign in to comment.