Skip to content

Commit

Permalink
Exclude popular keys from values lookups..
Browse files Browse the repository at this point in the history
see #3955
  • Loading branch information
bhousel committed Apr 19, 2017
1 parent b44bd7a commit c2d6c84
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion modules/services/taginfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { utilQsString } from '../util/index';

var endpoint = 'https://taginfo.openstreetmap.org/api/4/',
taginfoCache = {},
popularKeys = {},
tag_sorts = {
point: 'count_nodes',
vertex: 'count_nodes',
Expand Down Expand Up @@ -152,7 +153,29 @@ function request(url, debounce, callback) {

export default {

init: function() { taginfoCache = {}; },
init: function() {
taginfoCache = {};
popularKeys = {};

// Fetch popular keys. We'll exclude these from `values`
// lookups because they stress taginfo, and they aren't likely
// to yield meaningful autocomplete results.. see #3955
this.keys({
rp: 100,
sortname: 'values_all',
sortorder: 'desc',
page: 1,
debounce: false
}, function(err, data) {
if (err) return;
data.forEach(function(d) {
if (d === 'opening_hours') return; // exception
popularKeys[d.value] = true;
});
});
},


reset: function() { taginfoCache = {}; },


Expand Down Expand Up @@ -200,6 +223,13 @@ export default {


values: function(parameters, callback) {
// Exclude popular keys from values lookups.. see #3955
var key = parameters.key;
if (key && popularKeys[key]) {
callback(null, []);
return;
}

var debounce = parameters.debounce;
parameters = clean(setSort(setFilter(parameters)));
request(endpoint + 'key/values?' +
Expand Down

0 comments on commit c2d6c84

Please sign in to comment.