rombert commented on a change in pull request #43:
URL: 
https://github.com/apache/sling-org-apache-sling-resourceresolver/pull/43#discussion_r605041280



##########
File path: 
src/main/java/org/apache/sling/resourceresolver/impl/ResourceResolverImpl.java
##########
@@ -1046,37 +1053,60 @@ public String getParentResourceType(final String 
resourceType) {
     public boolean isResourceType(final Resource resource, final String 
resourceType) {
         boolean result = false;
         if ( resource != null && resourceType != null ) {
-             // Check if the resource is of the given type. This method first 
checks the
-             // resource type of the resource, then its super resource type 
and continues
-             //  to go up the resource super type hierarchy.
-             if (ResourceTypeUtil.areResourceTypesEqual(resourceType, 
resource.getResourceType(), factory.getSearchPath())) {
-                 result = true;
-             } else {
-                 Set<String> superTypesChecked = new HashSet<>();
-                 String superType = this.getParentResourceType(resource);
-                 while (!result && superType != null) {
-                     if (ResourceTypeUtil.areResourceTypesEqual(resourceType, 
superType, factory.getSearchPath())) {
-                         result = true;
-                     } else {
-                         superTypesChecked.add(superType);
-                         superType = this.getParentResourceType(superType);
-                         if (superType != null && 
superTypesChecked.contains(superType)) {
-                             throw new SlingException("Cyclic dependency for 
resourceSuperType hierarchy detected on resource " + resource.getPath(), null);
-                         }
-                     }
-                 }
+
+             // Check if the result is already available from cache
+             ResourceTypeInformation key = new 
ResourceTypeInformation(resource.getResourceType(),resource.getResourceSuperType(),
 resourceType);
+             Boolean value = resourceTypeLookupCache.get(key);

Review comment:
       Thinking about it some more, maybe a `ConcurrentMap` is a better fit? 
It's more expressive, e.g.
   
   ```java
   resourceTypeLookupCache.computeIfAbset(key, (key) -> 
isResourceTypeInternal(resource, resourceType));
   ```
   
   and also skips the locking of the synchronized map.
   
   If you're happy with the synchronized map, feel free to use that.




-- 
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to