joerghoh commented on a change in pull request #43:
URL:
https://github.com/apache/sling-org-apache-sling-resourceresolver/pull/43#discussion_r605180992
##########
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:
If the access is normally happening synchronously, the overhead of
locking seems acceptable to me compared to the overhead of a more complex
implementation. But unless we have benchmarked it's probably an academic
discussion :-)
--
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]