Skip to content

Commit

Permalink
Cache wikidata results
Browse files Browse the repository at this point in the history
Because wikidata field potentially shown on hover now
and the results of this lookup will never change
  • Loading branch information
bhousel committed Dec 2, 2018
1 parent f559fc5 commit 5a6671d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions modules/services/wikidata.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -42,6 +45,10 @@ export default {
callback('', {});
return;
}
if (_wikidataCache[qid]) {
callback('', _wikidataCache[qid]);
return
}

var lang = currentLocale.replace(/-/g, '_');

Expand All @@ -58,6 +65,7 @@ export default {
if (err || !data || data.error) {
callback('', {});
} else {
_wikidataCache[qid] = data.entities[qid];
callback(qid, data.entities[qid] || {});
}
});
Expand Down

0 comments on commit 5a6671d

Please sign in to comment.