Author: stillalex Date: Thu Nov 1 10:51:39 2018 New Revision: 1845439 URL: http://svn.apache.org/viewvc?rev=1845439&view=rev Log: OAK-7870 Reduce permission store lookups for empty principal sets
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/CompiledPermissionImpl.java Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/CompiledPermissionImpl.java URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/CompiledPermissionImpl.java?rev=1845439&r1=1845438&r2=1845439&view=diff ============================================================================== --- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/CompiledPermissionImpl.java (original) +++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authorization/permission/CompiledPermissionImpl.java Thu Nov 1 10:51:39 2018 @@ -109,8 +109,16 @@ final class CompiledPermissionImpl imple } } - userStore = new PermissionEntryProviderImpl(store, userNames, options); - groupStore = new PermissionEntryProviderImpl(store, groupNames, options); + if (!userNames.isEmpty()) { + userStore = new PermissionEntryProviderImpl(store, userNames, options); + } else { + userStore = null; + } + if (!groupNames.isEmpty()) { + groupStore = new PermissionEntryProviderImpl(store, groupNames, options); + } else { + groupStore = null; + } typeProvider = new TreeTypeProvider(ctx); } @@ -138,8 +146,12 @@ final class CompiledPermissionImpl imple this.versionManager = null; store.flush(root); - userStore.flush(); - groupStore.flush(); + if (userStore != null) { + userStore.flush(); + } + if (groupStore != null) { + groupStore.flush(); + } } @NotNull @@ -414,9 +426,17 @@ final class CompiledPermissionImpl imple @NotNull private Iterator<PermissionEntry> getEntryIterator(@NotNull EntryPredicate predicate) { - Iterator<PermissionEntry> userEntries = userStore.getEntryIterator(predicate); - Iterator<PermissionEntry> groupEntries = groupStore.getEntryIterator(predicate); - return concat(userEntries, groupEntries); + if (userStore != null && groupStore != null) { + Iterator<PermissionEntry> userEntries = userStore.getEntryIterator(predicate); + Iterator<PermissionEntry> groupEntries = groupStore.getEntryIterator(predicate); + return concat(userEntries, groupEntries); + } else if (userStore != null) { + return userStore.getEntryIterator(predicate); + } else if (groupStore != null) { + return groupStore.getEntryIterator(predicate); + } else { + return Collections.emptyIterator(); + } } @Nullable @@ -567,14 +587,14 @@ final class CompiledPermissionImpl imple private Iterator<PermissionEntry> getUserEntries() { if (userEntries == null) { - userEntries = userStore.getEntries(tree); + userEntries = userStore != null ? userStore.getEntries(tree) : Collections.emptyList(); } return userEntries.iterator(); } private Iterator<PermissionEntry> getGroupEntries() { if (groupEntries == null) { - groupEntries = groupStore.getEntries(tree); + groupEntries = groupStore != null ? groupStore.getEntries(tree) : Collections.emptyList(); } return groupEntries.iterator(); }