diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java index b0719131e1..c7d00a527c 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/GroupAdapter.java @@ -258,7 +258,7 @@ public class GroupAdapter implements GroupModel { @Override public Long getSubGroupsCount() { if (isUpdated()) return updated.getSubGroupsCount(); - return modelSupplier.get().getSubGroupsCount(); + return cached.getSubGroupsCount(modelSupplier); } @Override diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/entities/CachedGroup.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/entities/CachedGroup.java index 70f362cbf4..b18a8009b4 100755 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/entities/CachedGroup.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/entities/CachedGroup.java @@ -41,6 +41,7 @@ public class CachedGroup extends AbstractRevisioned implements InRealm { private final LazyLoader> attributes; private final LazyLoader> roleMappings; private final LazyLoader> subGroups; + private final LazyLoader subGroupsCount; public CachedGroup(Long revision, RealmModel realm, GroupModel group) { super(revision, group.getId()); @@ -50,6 +51,7 @@ public class CachedGroup extends AbstractRevisioned implements InRealm { this.attributes = new DefaultLazyLoader<>(source -> new MultivaluedHashMap<>(source.getAttributes()), MultivaluedHashMap::new); this.roleMappings = new DefaultLazyLoader<>(source -> source.getRoleMappingsStream().map(RoleModel::getId).collect(Collectors.toSet()), Collections::emptySet); this.subGroups = new DefaultLazyLoader<>(source -> source.getSubGroupsStream().map(GroupModel::getId).collect(Collectors.toSet()), Collections::emptySet); + this.subGroupsCount = new DefaultLazyLoader<>(GroupModel::getSubGroupsCount, () -> 0L); } public String getRealm() { @@ -79,4 +81,8 @@ public class CachedGroup extends AbstractRevisioned implements InRealm { public Set getSubGroups(Supplier group) { return subGroups.get(group); } + + public Long getSubGroupsCount(Supplier group) { + return subGroupsCount.get(group); + } }