From 599d2df19bb6dee31de120723000f006671ad5ed Mon Sep 17 00:00:00 2001 From: "Milos Brzakovic (E-Search)" Date: Wed, 20 Oct 2021 09:49:00 +0200 Subject: [PATCH] matchTags - don't calculcate valid locations unless needed mismatched_geometry - small optimization --- modules/presets/index.js | 30 ++++++++++++++-------- modules/validations/mismatched_geometry.js | 3 ++- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/modules/presets/index.js b/modules/presets/index.js index 6770f3994..51076d96d 100644 --- a/modules/presets/index.js +++ b/modules/presets/index.js @@ -208,11 +208,8 @@ export function presetIndex() { let address; let best = -1; let match; - + let matchCandidates = []; let validLocations; - if (Array.isArray(loc)) { - validLocations = locationManager.locationsAt(loc); - } for (let k in tags) { // If any part of an address is present, allow fallback to "Address" preset - #4353 @@ -225,13 +222,11 @@ export function presetIndex() { for (let i = 0; i < keyMatches.length; i++) { const candidate = keyMatches[i]; - - // discard candidate preset if location is not valid at `loc` - if (validLocations && candidate.locationSetID) { - if (!validLocations[candidate.locationSetID]) continue; - } - const score = candidate.matchScore(tags); + if (score === -1){ + continue; + } + matchCandidates.push({score, candidate}); if (score > best) { best = score; match = candidate; @@ -239,6 +234,21 @@ export function presetIndex() { } } + if (match && match.locationSetID && Array.isArray(loc)){ + validLocations = locationManager.locationsAt(loc); + if (!validLocations[match.locationSetID]){ + matchCandidates.sort((a, b) => (a.score < b.score) ? 1 : -1); + for (let i = 0; i < matchCandidates.length; i++){ + const candidateScore = matchCandidates[i]; + if (!candidateScore.candidate.locationSetID || validLocations[candidateScore.candidate.locationSetID]){ + match = candidateScore.candidate; + best = candidateScore.score; + break; + } + } + } + } + if (address && (!match || match.isFallback())) { match = address; } diff --git a/modules/validations/mismatched_geometry.js b/modules/validations/mismatched_geometry.js index 199cf238e..42fb0b4ef 100644 --- a/modules/validations/mismatched_geometry.js +++ b/modules/validations/mismatched_geometry.js @@ -220,8 +220,9 @@ export function validationMismatchedGeometry() { if (sourceGeom === 'area') targetGeoms.unshift('line'); + var asSource = presetManager.match(entity, graph); + var targetGeom = targetGeoms.find(nodeGeom => { - var asSource = presetManager.matchTags(entity.tags, sourceGeom); var asTarget = presetManager.matchTags(entity.tags, nodeGeom); if (!asSource || !asTarget || asSource === asTarget ||