From 821f5de3e325d9b19c4c31b3a9f7a0a28444cc41 Mon Sep 17 00:00:00 2001 From: David Rowe Date: Fri, 11 Aug 2017 10:20:36 +1200 Subject: [PATCH] Further reduce number of Entites.getEntityProperties() calls --- scripts/vr-edit/utilities/utilities.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/scripts/vr-edit/utilities/utilities.js b/scripts/vr-edit/utilities/utilities.js index d5f9d556f8..8dacec8c2d 100644 --- a/scripts/vr-edit/utilities/utilities.js +++ b/scripts/vr-edit/utilities/utilities.js @@ -33,7 +33,19 @@ if (typeof Uuid.SELF !== "string") { } if (typeof Entities.rootOf !== "function") { + Entities.rootOfCache = { + CACHE_ENTRY_EXPIRY_TIME: 1000 // ms + }; + Entities.rootOf = function (entityID) { + if (Entities.rootOfCache[entityID]) { + if (Date.now() - Entities.rootOfCache[entityID].timeStamp + < Entities.rootOfCache.CACHE_ENTRY_EXPIRY_TIME) { + return Entities.rootOfCache[entityID].rootOf; + } + delete Entities.rootOfCache[entityID]; + } + var rootEntityID, entityProperties, PARENT_PROPERTIES = ["parentID"]; @@ -43,6 +55,11 @@ if (typeof Entities.rootOf !== "function") { rootEntityID = entityProperties.parentID; entityProperties = Entities.getEntityProperties(rootEntityID, PARENT_PROPERTIES); } + + Entities.rootOfCache[entityID] = { + rootOf: rootEntityID, + timeStamp: Date.now() + }; return rootEntityID; }; } @@ -71,6 +88,7 @@ if (typeof Entities.hasEditableRoot !== "function") { properties = Entities.getEntityProperties(properties.parentID, EDITIBLE_ENTITY_QUERY_PROPERTYES); } isEditable = properties.visible && !properties.locked && NONEDITABLE_ENTITY_TYPES.indexOf(properties.type) === -1; + Entities.hasEditableRootCache[entityID] = { hasEditableRoot: isEditable, timeStamp: Date.now()