From d3069a47ae7937cd6bf1ea8bb4c7cdb65fddc5de Mon Sep 17 00:00:00 2001 From: Til Schneider Date: Wed, 26 Aug 2020 13:05:34 +0200 Subject: [PATCH 1/2] Improve performance of raw tag editor The detection whether `_entityIDs ` includes a relation is performed many times inside a loop. Instead this should be done only once (lazy). --- modules/ui/sections/raw_tag_editor.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/modules/ui/sections/raw_tag_editor.js b/modules/ui/sections/raw_tag_editor.js index b24a0a75b..52320cc26 100644 --- a/modules/ui/sections/raw_tag_editor.js +++ b/modules/ui/sections/raw_tag_editor.js @@ -215,6 +215,7 @@ export function uiSectionRawTagEditor(id, context) { .merge(itemsEnter) .sort(function(a, b) { return a.index - b.index; }); + var includesRelation = null; items .each(function(d) { var row = d3_select(this); @@ -230,10 +231,12 @@ export function uiSectionRawTagEditor(id, context) { if (typeof d.value !== 'string') { reference = uiTagReference({ key: d.key }, context); } else { - var isRelation = _entityIDs && _entityIDs.some(function(entityID) { - return context.entity(entityID).type === 'relation'; - }); - if (isRelation && d.key === 'type') { + if (includesRelation === null) { + includesRelation = _entityIDs && _entityIDs.some(function(entityID) { + return context.entity(entityID).type === 'relation'; + }); + } + if (includesRelation && d.key === 'type') { reference = uiTagReference({ rtype: d.value }, context); } else { reference = uiTagReference({ key: d.key, value: d.value }, context); From 4dabd79702c871f1e77ce809fcfb94c24e9e21a0 Mon Sep 17 00:00:00 2001 From: Til Schneider Date: Sat, 29 Aug 2020 11:05:07 +0200 Subject: [PATCH 2/2] Move relation type detection to osm_wikibase (#7932) --- modules/services/osm_wikibase.js | 7 +------ modules/ui/sections/raw_tag_editor.js | 20 ++++---------------- modules/ui/tag_reference.js | 6 +----- 3 files changed, 6 insertions(+), 27 deletions(-) diff --git a/modules/services/osm_wikibase.js b/modules/services/osm_wikibase.js index a5ff0a545..f56f825b5 100644 --- a/modules/services/osm_wikibase.js +++ b/modules/services/osm_wikibase.js @@ -124,7 +124,6 @@ export default { // { // key: 'string', // value: 'string', - // rtype: 'string', // langCode: 'string' // } // @@ -133,7 +132,7 @@ export default { var that = this; var titles = []; var result = {}; - var rtypeSitelink = params.rtype ? ('Relation:' + params.rtype).replace(/_/g, ' ').trim() : false; + var rtypeSitelink = (params.key === 'type' && params.value) ? ('Relation:' + params.value).replace(/_/g, ' ').trim() : false; var keySitelink = params.key ? this.toSitelink(params.key) : false; var tagSitelink = (params.key && params.value) ? this.toSitelink(params.key, params.value) : false; var localeSitelink; @@ -242,10 +241,6 @@ export default { // key: 'string', // required // value: 'string' // optional // } - // -or- - // { - // rtype: 'rtype' // relation type (e.g. 'multipolygon') - // } // // Get an result object used to display tag documentation // { diff --git a/modules/ui/sections/raw_tag_editor.js b/modules/ui/sections/raw_tag_editor.js index 52320cc26..4fcb9b3c8 100644 --- a/modules/ui/sections/raw_tag_editor.js +++ b/modules/ui/sections/raw_tag_editor.js @@ -215,7 +215,6 @@ export function uiSectionRawTagEditor(id, context) { .merge(itemsEnter) .sort(function(a, b) { return a.index - b.index; }); - var includesRelation = null; items .each(function(d) { var row = d3_select(this); @@ -226,22 +225,11 @@ export function uiSectionRawTagEditor(id, context) { bindTypeahead(key, value); } - var reference; - - if (typeof d.value !== 'string') { - reference = uiTagReference({ key: d.key }, context); - } else { - if (includesRelation === null) { - includesRelation = _entityIDs && _entityIDs.some(function(entityID) { - return context.entity(entityID).type === 'relation'; - }); - } - if (includesRelation && d.key === 'type') { - reference = uiTagReference({ rtype: d.value }, context); - } else { - reference = uiTagReference({ key: d.key, value: d.value }, context); - } + var referenceOptions = { key: d.key }; + if (typeof d.value === 'string') { + referenceOptions.value = d.value; } + var reference = uiTagReference(referenceOptions, context); if (_state === 'hover') { reference.showing(false); diff --git a/modules/ui/tag_reference.js b/modules/ui/tag_reference.js index 7bf02fd1e..123bff2b0 100644 --- a/modules/ui/tag_reference.js +++ b/modules/ui/tag_reference.js @@ -8,17 +8,13 @@ import { services } from '../services'; import { svgIcon } from '../svg/icon'; -// Pass `which` object of the form: +// Pass `what` object of the form: // { // key: 'string', // required // value: 'string' // optional // } // -or- // { -// rtype: 'string' // relation type (e.g. 'multipolygon') -// } -// -or- -// { // qid: 'string' // brand wikidata (e.g. 'Q37158') // } //