From 93373b93989171a15bf18f6ce2ae33bbf485d513 Mon Sep 17 00:00:00 2001 From: Alexander Schwartz Date: Fri, 5 May 2023 10:55:16 +0200 Subject: [PATCH] Cache theme root URI This is a performance optimization. Closes #20176 --- .../forms/login/freemarker/model/UrlBean.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/services/src/main/java/org/keycloak/forms/login/freemarker/model/UrlBean.java b/services/src/main/java/org/keycloak/forms/login/freemarker/model/UrlBean.java index 599dc1484b..1a48eb7e7f 100755 --- a/services/src/main/java/org/keycloak/forms/login/freemarker/model/UrlBean.java +++ b/services/src/main/java/org/keycloak/forms/login/freemarker/model/UrlBean.java @@ -36,6 +36,7 @@ public class UrlBean { private URI baseURI; private Theme theme; private String realm; + private URI themeRootUri; public UrlBean(RealmModel realm, Theme theme, URI baseURI, URI actionUri) { this.realm = realm != null ? realm.getName() : null; @@ -103,7 +104,7 @@ public class UrlBean { } public String getResourcesUrl() { - return Urls.themeRoot(baseURI).toString() + "/" + theme.getType().toString().toLowerCase() +"/" + theme.getName(); + return getThemeRootUri().toString() + "/" + theme.getType().toString().toLowerCase() +"/" + theme.getName(); } public String getOauthAction() { @@ -123,12 +124,12 @@ public class UrlBean { } public String getResourcesPath() { - URI uri = Urls.themeRoot(baseURI); + URI uri = getThemeRootUri(); return uri.getPath() + "/" + theme.getType().toString().toLowerCase() +"/" + theme.getName(); } public String getResourcesCommonPath() { - URI uri = Urls.themeRoot(baseURI); + URI uri = getThemeRootUri(); String commonPath = ""; try { commonPath = theme.getProperties().getProperty("import"); @@ -140,4 +141,11 @@ public class UrlBean { } return uri.getPath() + "/" + commonPath; } + + private URI getThemeRootUri() { + if (themeRootUri == null) { + themeRootUri = Urls.themeRoot(baseURI); + } + return themeRootUri; + } }