From d3069a47ae7937cd6bf1ea8bb4c7cdb65fddc5de Mon Sep 17 00:00:00 2001 From: Til Schneider Date: Wed, 26 Aug 2020 13:05:34 +0200 Subject: [PATCH] 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);