Cache wikidata results

Because wikidata field potentially shown on hover now
and the results of this lookup will never change
This commit is contained in:
Bryan Housel
2018-12-01 22:06:17 -05:00
parent f559fc57bb
commit 5a6671d728
+10 -2
View File
@@ -1,15 +1,18 @@
import { json as d3_json } from 'd3-request';
import { utilQsString } from '../util';
import { currentLocale } from '../util/locale';
var endpoint = 'https://www.wikidata.org/w/api.php?';
var _wikidataCache = {};
export default {
init: function() {},
reset: function() {},
reset: function() {
_wikidataCache = {};
},
// Given a Wikipedia language and article title, return an array of
@@ -42,6 +45,10 @@ export default {
callback('', {});
return;
}
if (_wikidataCache[qid]) {
callback('', _wikidataCache[qid]);
return
}
var lang = currentLocale.replace(/-/g, '_');
@@ -58,6 +65,7 @@ export default {
if (err || !data || data.error) {
callback('', {});
} else {
_wikidataCache[qid] = data.entities[qid];
callback(qid, data.entities[qid] || {});
}
});