Use session level cache and avoid resolving by ID too often
Closes #12381
This commit is contained in:
parent
0c654fa53b
commit
27ecf7f00f
2 changed files with 15 additions and 15 deletions
|
@ -104,13 +104,19 @@ public abstract class JpaMapKeycloakTransaction<RE extends JpaRootEntity, E exte
|
||||||
@Override
|
@Override
|
||||||
public E read(String key) {
|
public E read(String key) {
|
||||||
if (key == null) return null;
|
if (key == null) return null;
|
||||||
|
E e = null;
|
||||||
|
if (!LockObjectsForModification.isEnabled(session, modelType)) {
|
||||||
|
e = cacheWithinSession.get(key);
|
||||||
|
}
|
||||||
|
if (e == null) {
|
||||||
UUID uuid = StringKeyConverter.UUIDKey.INSTANCE.fromStringSafe(key);
|
UUID uuid = StringKeyConverter.UUIDKey.INSTANCE.fromStringSafe(key);
|
||||||
if (uuid == null) return null;
|
if (uuid == null) return null;
|
||||||
E e = mapToEntityDelegateUnique(
|
e = mapToEntityDelegateUnique(
|
||||||
LockObjectsForModification.isEnabled(session, modelType) ?
|
LockObjectsForModification.isEnabled(session, modelType) ?
|
||||||
em.find(entityType, uuid, LockModeType.PESSIMISTIC_WRITE) :
|
em.find(entityType, uuid, LockModeType.PESSIMISTIC_WRITE) :
|
||||||
em.find(entityType, uuid)
|
em.find(entityType, uuid)
|
||||||
);
|
);
|
||||||
|
}
|
||||||
return e != null && isExpirableEntity && isExpired((ExpirableEntity) e, true) ? null : e;
|
return e != null && isExpirableEntity && isExpired((ExpirableEntity) e, true) ? null : e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -191,13 +191,10 @@ public class MapRoleProvider implements RoleProvider {
|
||||||
.compare(SearchableFields.IS_CLIENT_ROLE, Operator.NE, true)
|
.compare(SearchableFields.IS_CLIENT_ROLE, Operator.NE, true)
|
||||||
.compare(SearchableFields.NAME, Operator.EQ, name);
|
.compare(SearchableFields.NAME, Operator.EQ, name);
|
||||||
|
|
||||||
String roleId = tx.read(withCriteria(mcb))
|
return tx.read(withCriteria(mcb))
|
||||||
.map(entityToAdapterFunc(realm))
|
.map(entityToAdapterFunc(realm))
|
||||||
.map(RoleModel::getId)
|
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
//we need to go via session.roles() not to bypass cache
|
|
||||||
return roleId == null ? null : session.roles().getRoleById(realm, roleId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -212,13 +209,10 @@ public class MapRoleProvider implements RoleProvider {
|
||||||
.compare(SearchableFields.CLIENT_ID, Operator.EQ, client.getId())
|
.compare(SearchableFields.CLIENT_ID, Operator.EQ, client.getId())
|
||||||
.compare(SearchableFields.NAME, Operator.EQ, name);
|
.compare(SearchableFields.NAME, Operator.EQ, name);
|
||||||
|
|
||||||
String roleId = tx.read(withCriteria(mcb))
|
return tx.read(withCriteria(mcb))
|
||||||
.map(entityToAdapterFunc(client.getRealm()))
|
.map(entityToAdapterFunc(client.getRealm()))
|
||||||
.map(RoleModel::getId)
|
|
||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
//we need to go via session.roles() not to bypass cache
|
|
||||||
return roleId == null ? null : session.roles().getRoleById(client.getRealm(), roleId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue