Skip to content

Commit 53f2871

Browse files
committed
fix(services): load 50+ entities
1 parent ad7d35b commit 53f2871

1 file changed

Lines changed: 23 additions & 14 deletions

File tree

src/services/wikidata.service.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,33 @@ const wdService = function ($http, $q, langService) {
4848
}
4949

5050
function getLabels(ids) {
51-
return get({
52-
ids,
53-
props: ['labels'],
54-
}).then(response => mapValues(response.entities, entity => simplifyLabels(entity.labels)));
51+
const promises = [];
52+
for (let i = 0; i < Math.ceil(ids.length / 50); i += 1) {
53+
promises.push(get({
54+
ids: ids.slice(i * 50, ((i + 1) * 50) - 1),
55+
props: ['labels'],
56+
}));
57+
}
58+
return $q.all(promises).then((responses) => {
59+
const result = {};
60+
responses.forEach((response) => {
61+
const values = mapValues(response.entities, entity => simplifyLabels(entity.labels));
62+
angular.extend(result, values);
63+
});
64+
return result;
65+
});
5566
}
5667

5768
function getRecursive(element, recursiveProperty) {
58-
let query = `SELECT ?parent ?parentLabel WHERE {
59-
wd:`+ element + ` ` + recursiveProperty + `* ?parent .
60-
SERVICE wikibase:label { bd:serviceParam wikibase:language "` + defaultParams.languages.join(', ') + `" }
69+
const query = `SELECT ?parent ?parentLabel WHERE {
70+
wd:${element} ${recursiveProperty}* ?parent .
71+
SERVICE wikibase:label { bd:serviceParam wikibase:language "${defaultParams.languages.join(', ')}" }
6172
}`;
62-
return getSPARQL(query).then(data => {
63-
return data.map(element => ({
64-
link: element.parent.value.replace('entity', 'wiki'),
65-
value_id: element.parent.value.substring(element.parent.value.indexOf('/Q') + 1),
66-
value: element.parentLabel.value
67-
}));
68-
});
73+
return getSPARQL(query).then(data => data.map((element) => ({
74+
link: element.parent.value.replace('entity', 'wiki'),
75+
value_id: element.parent.value.substring(element.parent.value.indexOf('/Q') + 1),
76+
value: element.parentLabel.value,
77+
})));
6978
}
7079

7180
function getSearch(text) {

0 commit comments

Comments
 (0)