Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove slow search via getTopLevelGroupsStream() for updating groups … #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,14 @@ public Response updateGroup(GroupRepresentation rep) {
}

if (!Objects.equals(groupName, group.getName())) {
boolean exists = siblings().filter(s -> !Objects.equals(s.getId(), group.getId()))
.anyMatch(s -> Objects.equals(s.getName(), groupName));
boolean exists;
if (group.getParentId() == null) {
exists = session.groups().searchForGroupByNameStream(realm, groupName, true, null, null)
.anyMatch(s -> !Objects.equals(s.getId(), group.getId()));
} else {
exists = group.getParent().getSubGroupsStream().filter(s -> !Objects.equals(s.getId(), group.getId()))
.anyMatch(s -> Objects.equals(s.getName(), groupName));
}
if (exists) {
throw ErrorResponse.exists("Sibling group named '" + groupName + "' already exists.");
}
Expand All @@ -133,14 +139,6 @@ public Response updateGroup(GroupRepresentation rep) {
return Response.noContent().build();
}

private Stream<GroupModel> siblings() {
if (group.getParentId() == null) {
return session.groups().getTopLevelGroupsStream(realm);
} else {
return group.getParent().getSubGroupsStream();
}
}

@DELETE
@Tag(name = KeycloakOpenAPI.Admin.Tags.GROUPS)
@Operation()
Expand Down
Loading