Map Store Removal: Remove obsolete KeycloakModelUtils.isRealmProviderJpa method
Closes #27445 Signed-off-by: vramik <vramik@redhat.com>
This commit is contained in:
parent
f1e7c572da
commit
7adcc98c6c
2 changed files with 13 additions and 33 deletions
|
@ -34,7 +34,6 @@ import org.keycloak.models.RealmModel;
|
||||||
import org.keycloak.models.jpa.entities.RealmAttributeEntity;
|
import org.keycloak.models.jpa.entities.RealmAttributeEntity;
|
||||||
import org.keycloak.models.jpa.entities.RealmAttributes;
|
import org.keycloak.models.jpa.entities.RealmAttributes;
|
||||||
import org.keycloak.models.jpa.entities.RealmEntity;
|
import org.keycloak.models.jpa.entities.RealmEntity;
|
||||||
import org.keycloak.models.utils.KeycloakModelUtils;
|
|
||||||
|
|
||||||
import jakarta.persistence.EntityManager;
|
import jakarta.persistence.EntityManager;
|
||||||
import jakarta.persistence.TypedQuery;
|
import jakarta.persistence.TypedQuery;
|
||||||
|
@ -84,11 +83,8 @@ public class JpaEventStoreProvider implements EventStoreProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void clearExpiredEvents() {
|
public void clearExpiredEvents() {
|
||||||
// By default, realm provider is always "jpa", so we can optimize and delete all events in single SQL, assuming that realms are saved in the DB as well.
|
|
||||||
// Fallback to model API just with different realm provider than "jpa" (This is never the case in standard Keycloak installations)
|
|
||||||
int numDeleted = 0;
|
int numDeleted = 0;
|
||||||
long currentTimeMillis = Time.currentTimeMillis();
|
long currentTimeMillis = Time.currentTimeMillis();
|
||||||
if (KeycloakModelUtils.isRealmProviderJpa(session)) {
|
|
||||||
|
|
||||||
// Group realms by expiration times. This will be effective if different realms have same/similar event expiration times, which will probably be the case in most environments
|
// Group realms by expiration times. This will be effective if different realms have same/similar event expiration times, which will probably be the case in most environments
|
||||||
List<Long> eventExpirations = em.createQuery("select distinct realm.eventsExpiration from RealmEntity realm where realm.eventsExpiration > 0").getResultList();
|
List<Long> eventExpirations = em.createQuery("select distinct realm.eventsExpiration from RealmEntity realm where realm.eventsExpiration > 0").getResultList();
|
||||||
|
@ -104,14 +100,6 @@ public class JpaEventStoreProvider implements EventStoreProvider {
|
||||||
numDeleted += currentNumDeleted;
|
numDeleted += currentNumDeleted;
|
||||||
}
|
}
|
||||||
logger.debugf("Cleared %d expired events in all realms", numDeleted);
|
logger.debugf("Cleared %d expired events in all realms", numDeleted);
|
||||||
} else {
|
|
||||||
session.realms().getRealmsStream().forEach(realm -> {
|
|
||||||
if (realm.isEventsEnabled() && realm.getEventsExpiration() > 0) {
|
|
||||||
long olderThan = Time.currentTimeMillis() - realm.getEventsExpiration() * 1000;
|
|
||||||
clear(realm, olderThan);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -978,14 +978,6 @@ public final class KeycloakModelUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @return true if implementation of realmProvider is "jpa" . Which is always the case in standard Keycloak installations.
|
|
||||||
*/
|
|
||||||
public static boolean isRealmProviderJpa(KeycloakSession session) {
|
|
||||||
Set<String> providerIds = session.listProviderIds(RealmProvider.class);
|
|
||||||
return providerIds != null && providerIds.size() == 1 && providerIds.iterator().next().equals("jpa");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param clientAuthenticatorType
|
* @param clientAuthenticatorType
|
||||||
* @return secret size based on authentication type
|
* @return secret size based on authentication type
|
||||||
|
|
Loading…
Reference in a new issue