Use entity locking only for the map storage

This is a performance optimization that the new feature doesn't affect the old store.

Closes #20176
This commit is contained in:
Alexander Schwartz 2023-05-05 13:46:48 +02:00 committed by Michal Hajas
parent bd7f62acc3
commit 910021408e

View file

@ -17,6 +17,7 @@
package org.keycloak.utils; package org.keycloak.utils;
import org.keycloak.common.Profile;
import org.keycloak.models.KeycloakSession; import org.keycloak.models.KeycloakSession;
import org.keycloak.models.RealmModel; import org.keycloak.models.RealmModel;
import org.keycloak.models.UserSessionModel; import org.keycloak.models.UserSessionModel;
@ -71,6 +72,11 @@ public class LockObjectsForModification {
} }
private static <V> V lockObjectsForModification(KeycloakSession session, Class<?> model, CallableWithoutThrowingAnException<V> callable) { private static <V> V lockObjectsForModification(KeycloakSession session, Class<?> model, CallableWithoutThrowingAnException<V> callable) {
// Only map storage supports locking objects for modification, skip the logic if it is not enabled.
if (!Profile.isFeatureEnabled(Profile.Feature.MAP_STORAGE)) {
return callable.call();
}
if (LockObjectsForModification.isEnabled(session, model)) { if (LockObjectsForModification.isEnabled(session, model)) {
// If someone nests the call, and it would already be locked, don't try to lock it a second time. // If someone nests the call, and it would already be locked, don't try to lock it a second time.
// Otherwise, the inner unlocking might also unlock the outer lock. // Otherwise, the inner unlocking might also unlock the outer lock.