jsedding commented on code in PR #115: URL: https://github.com/apache/sling-org-apache-sling-resourceresolver/pull/115#discussion_r1961338722
########## src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java: ########## @@ -1054,14 +1058,41 @@ public boolean hasChildren(Resource resource) { public String getParentResourceType(final Resource resource) { String resourceSuperType = null; if ( resource != null ) { - resourceSuperType = resource.getResourceSuperType(); - if (resourceSuperType == null) { - resourceSuperType = this.getParentResourceType(resource.getResourceType()); + if (getParentResourceTypeMap().containsKey(resource.getPath())) { + resourceSuperType = getParentResourceTypeMap().get(resource.getPath()); + } else { + resourceSuperType = getParentResourceTypeInternal(resource); + getParentResourceTypeMap().put(resource.getPath(), resourceSuperType); } } return resourceSuperType; } + String getParentResourceTypeInternal(final Resource resource) { + String resourceSuperType; + resourceSuperType = resource.getResourceSuperType(); + if (resourceSuperType == null) { + resourceSuperType = this.getParentResourceType(resource.getResourceType()); + } + return resourceSuperType; + } + + /** + * get the map to hold the resourceType - parentResourceType relations + * @return the map + */ + private @NotNull Map<String,String> getParentResourceTypeMap() { + @SuppressWarnings("unchecked") + Map<String,String> result = (Map<String, String>) getPropertyMap().get(PARENT_RT_CACHEKEY); + if (result == null) { + result = new HashMap<>(); + getPropertyMap().put(PARENT_RT_CACHEKEY, result); + } + return result; + } Review Comment: This can be simplified: ```suggestion private @NotNull Map<String,String> getParentResourceTypeMap() { @SuppressWarnings("unchecked") return (Map<String, String>) getPropertyMap().computeIfAbsent(PARENT_RT_CACHEKEY, k -> new HashMap<>()); } ``` ########## src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java: ########## @@ -1054,14 +1058,41 @@ public boolean hasChildren(Resource resource) { public String getParentResourceType(final Resource resource) { String resourceSuperType = null; if ( resource != null ) { - resourceSuperType = resource.getResourceSuperType(); - if (resourceSuperType == null) { - resourceSuperType = this.getParentResourceType(resource.getResourceType()); + if (getParentResourceTypeMap().containsKey(resource.getPath())) { + resourceSuperType = getParentResourceTypeMap().get(resource.getPath()); + } else { + resourceSuperType = getParentResourceTypeInternal(resource); + getParentResourceTypeMap().put(resource.getPath(), resourceSuperType); Review Comment: Can be simplified: ```suggestion resourceSuperType = getParentResourceTypeMap().computeIfAbsent(resource.getPath(), p -> getParentResourceTypeInternal(resource)); ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@sling.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org