Avoid duplicates when storing organization ids

Signed-off-by: Michal Hajas <mhajas@redhat.com>
This commit is contained in:
Michal Hajas 2024-09-30 16:35:40 +02:00 committed by Pedro Igor
parent 0becdaa2a9
commit c682536dae

View file

@ -19,6 +19,7 @@ package org.keycloak.models.cache.infinispan.organization;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.keycloak.models.OrganizationModel; import org.keycloak.models.OrganizationModel;
@ -40,8 +41,8 @@ public class CachedOrganizationIds extends AbstractRevisioned implements InRealm
public CachedOrganizationIds(Long revision, String id, RealmModel realm, Stream<OrganizationModel> models) { public CachedOrganizationIds(Long revision, String id, RealmModel realm, Stream<OrganizationModel> models) {
super(revision, id); super(revision, id);
this.realmId = realm.getId(); this.realmId = realm.getId();
var ids = models.map(OrganizationModel::getId).toList(); var ids = models.map(OrganizationModel::getId).collect(Collectors.toSet());
orgIds = ids.isEmpty() ? List.of() : ids; orgIds = ids.isEmpty() ? List.of() : List.of(ids.toArray(new String[0]));
} }
public Collection<String> getOrgIds() { public Collection<String> getOrgIds() {