From c626228b70a9d99adf1fff877b0af3ddec140bf4 Mon Sep 17 00:00:00 2001 From: Simon Brown Date: Thu, 7 Dec 2023 11:34:41 +0000 Subject: [PATCH] Prevents pre-built themes being loaded during server-side automatic layout execution ... they have no element width/height definitions, and the themes have no impact on automatic layout. --- .../web/graphviz/GraphvizController.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/structurizr-onpremises/src/main/java/com/structurizr/onpremises/web/graphviz/GraphvizController.java b/structurizr-onpremises/src/main/java/com/structurizr/onpremises/web/graphviz/GraphvizController.java index ee7cc44..131197e 100644 --- a/structurizr-onpremises/src/main/java/com/structurizr/onpremises/web/graphviz/GraphvizController.java +++ b/structurizr-onpremises/src/main/java/com/structurizr/onpremises/web/graphviz/GraphvizController.java @@ -17,12 +17,15 @@ import java.io.File; import java.nio.file.Files; +import java.util.Arrays; @RestController public class GraphvizController { private static final Log log = LogFactory.getLog(GraphvizController.class); + private static final String PREBUILT_THEME_URL = "https://static.structurizr.com"; + @PostMapping(value = "/graphviz", consumes = "application/json", produces = "application/json; charset=UTF-8") public String post(@RequestBody String json, @RequestParam(required = false) String view, @@ -38,9 +41,11 @@ public String post(@RequestBody String json, Workspace workspace = WorkspaceUtils.fromJson(json); if (configuration.hasInternetConnection()) { - log.debug("Loading themes"); try { - ThemeUtils.loadThemes(workspace); + if (themesNeedToBeLoaded(workspace)) { + log.debug("Loading themes"); + ThemeUtils.loadThemes(workspace); + } } catch (Exception e) { log.warn("Ignoring themes: " + e.getMessage()); } @@ -130,4 +135,10 @@ public String post(@RequestBody String json, } } + private boolean themesNeedToBeLoaded(Workspace workspace) { + // the pre-built themes at https://static.structurizr.com do not include any element width/height definitions, + // and therefore don't need to be loaded in order to run automatic layout + return Arrays.stream(workspace.getViews().getConfiguration().getThemes()).anyMatch(t -> !t.startsWith(PREBUILT_THEME_URL)); + } + } \ No newline at end of file