diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/organization/CachedOrganizationIds.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/organization/CachedOrganizationIds.java index 23323092dd..90a0394a9b 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/organization/CachedOrganizationIds.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/organization/CachedOrganizationIds.java @@ -17,8 +17,8 @@ package org.keycloak.models.cache.infinispan.organization; -import java.util.HashSet; -import java.util.Set; +import java.util.Collection; +import java.util.List; import java.util.stream.Stream; import org.keycloak.models.OrganizationModel; @@ -28,21 +28,28 @@ import org.keycloak.models.cache.infinispan.entities.InRealm; public class CachedOrganizationIds extends AbstractRevisioned implements InRealm { - private final RealmModel realm; - private final Set orgIds = new HashSet<>(); + private final String realmId; + private final List orgIds; - public CachedOrganizationIds(Long revision, String id, RealmModel realm, Stream organizations) { + public CachedOrganizationIds(Long revision, String id, RealmModel realm, OrganizationModel model) { super(revision, id); - this.realm = realm; - organizations.map(OrganizationModel::getId).forEach(orgIds::add); + this.realmId = realm.getId(); + orgIds = List.of(model.getId()); + } + + public CachedOrganizationIds(Long revision, String id, RealmModel realm, Stream models) { + super(revision, id); + this.realmId = realm.getId(); + var ids = models.map(OrganizationModel::getId).toList(); + orgIds = ids.isEmpty() ? List.of() : ids; + } + + public Collection getOrgIds() { + return orgIds; } @Override public String getRealm() { - return realm.getId(); - } - - public Set getOrgIds() { - return orgIds; + return realmId; } } diff --git a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/organization/InfinispanOrganizationProvider.java b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/organization/InfinispanOrganizationProvider.java index f3234a225a..d2bf3b4340 100644 --- a/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/organization/InfinispanOrganizationProvider.java +++ b/model/infinispan/src/main/java/org/keycloak/models/cache/infinispan/organization/InfinispanOrganizationProvider.java @@ -112,7 +112,7 @@ public class InfinispanOrganizationProvider implements OrganizationProvider { if (model == null) { return null; } - cached = new CachedOrganizationIds(loaded, cacheKey, getRealm(), Stream.of(model)); + cached = new CachedOrganizationIds(loaded, cacheKey, getRealm(), model); realmCache.getCache().addRevisioned(cached, realmCache.getStartupRevision()); }