Add caching for subGroupsCount

Closes #25731

Signed-off-by: Michal Hajas <mhajas@redhat.com>
This commit is contained in:
Michal Hajas 2024-02-08 17:06:10 +01:00 committed by Pedro Igor
parent e55ba5dcdc
commit f7f7f1bd10
2 changed files with 7 additions and 1 deletions

View file

@ -258,7 +258,7 @@ public class GroupAdapter implements GroupModel {
@Override @Override
public Long getSubGroupsCount() { public Long getSubGroupsCount() {
if (isUpdated()) return updated.getSubGroupsCount(); if (isUpdated()) return updated.getSubGroupsCount();
return modelSupplier.get().getSubGroupsCount(); return cached.getSubGroupsCount(modelSupplier);
} }
@Override @Override

View file

@ -41,6 +41,7 @@ public class CachedGroup extends AbstractRevisioned implements InRealm {
private final LazyLoader<GroupModel, MultivaluedHashMap<String, String>> attributes; private final LazyLoader<GroupModel, MultivaluedHashMap<String, String>> attributes;
private final LazyLoader<GroupModel, Set<String>> roleMappings; private final LazyLoader<GroupModel, Set<String>> roleMappings;
private final LazyLoader<GroupModel, Set<String>> subGroups; private final LazyLoader<GroupModel, Set<String>> subGroups;
private final LazyLoader<GroupModel, Long> subGroupsCount;
public CachedGroup(Long revision, RealmModel realm, GroupModel group) { public CachedGroup(Long revision, RealmModel realm, GroupModel group) {
super(revision, group.getId()); 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.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.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.subGroups = new DefaultLazyLoader<>(source -> source.getSubGroupsStream().map(GroupModel::getId).collect(Collectors.toSet()), Collections::emptySet);
this.subGroupsCount = new DefaultLazyLoader<>(GroupModel::getSubGroupsCount, () -> 0L);
} }
public String getRealm() { public String getRealm() {
@ -79,4 +81,8 @@ public class CachedGroup extends AbstractRevisioned implements InRealm {
public Set<String> getSubGroups(Supplier<GroupModel> group) { public Set<String> getSubGroups(Supplier<GroupModel> group) {
return subGroups.get(group); return subGroups.get(group);
} }
public Long getSubGroupsCount(Supplier<GroupModel> group) {
return subGroupsCount.get(group);
}
} }