Add caching for subGroupsCount
Closes #25731 Signed-off-by: Michal Hajas <mhajas@redhat.com>
This commit is contained in:
parent
e55ba5dcdc
commit
f7f7f1bd10
2 changed files with 7 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -41,6 +41,7 @@ public class CachedGroup extends AbstractRevisioned implements InRealm {
|
|||
private final LazyLoader<GroupModel, MultivaluedHashMap<String, String>> attributes;
|
||||
private final LazyLoader<GroupModel, Set<String>> roleMappings;
|
||||
private final LazyLoader<GroupModel, Set<String>> subGroups;
|
||||
private final LazyLoader<GroupModel, Long> 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<String> getSubGroups(Supplier<GroupModel> group) {
|
||||
return subGroups.get(group);
|
||||
}
|
||||
|
||||
public Long getSubGroupsCount(Supplier<GroupModel> group) {
|
||||
return subGroupsCount.get(group);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue