From dee1cec290bfaaf004903f85e5c5d70b0c1dcc54 Mon Sep 17 00:00:00 2001 From: ashwingroot <73108778+imashwin-v@users.noreply.github.com> Date: Thu, 26 Oct 2023 19:47:32 +0530 Subject: [PATCH] fix to preload offline sessions faster slow loading offline tokens during start up leads to connection timeout closes #24295 --- .../jpa/session/JpaUserSessionPersisterProvider.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/model/jpa/src/main/java/org/keycloak/models/jpa/session/JpaUserSessionPersisterProvider.java b/model/jpa/src/main/java/org/keycloak/models/jpa/session/JpaUserSessionPersisterProvider.java index 935863f971..3bdfd6f76d 100644 --- a/model/jpa/src/main/java/org/keycloak/models/jpa/session/JpaUserSessionPersisterProvider.java +++ b/model/jpa/src/main/java/org/keycloak/models/jpa/session/JpaUserSessionPersisterProvider.java @@ -519,13 +519,15 @@ public class JpaUserSessionPersisterProvider implements UserSessionPersisterProv model.setClientId(clientId); model.setUserSessionId(userSession.getId()); - UserModel user = userSession.getUser(); - if (user != null) { - model.setUserId(user.getId()); - } - else if (userSession instanceof PersistentUserSessionAdapter) { + if (userSession instanceof PersistentUserSessionAdapter) { model.setUserId(((PersistentUserSessionAdapter) userSession).getUserId()); } + else { + UserModel user = userSession.getUser(); + if (user != null) { + model.setUserId(user.getId()); + } + } model.setTimestamp(entity.getTimestamp()); model.setData(entity.getData()); return new PersistentAuthenticatedClientSessionAdapter(session, model, realm, client, userSession);