mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-22 08:17:30 +02:00
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:
@@ -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] || {});
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user