From 6201add3eda591101dd350db60d1a9c0423f514b Mon Sep 17 00:00:00 2001 From: Andreas Resch Date: Thu, 21 Dec 2023 20:24:55 +0100 Subject: [PATCH] cache windfiles on startup --- .../aeolus/AeolusTemplateService.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/tum/in/www1/artemis/service/connectors/aeolus/AeolusTemplateService.java b/src/main/java/de/tum/in/www1/artemis/service/connectors/aeolus/AeolusTemplateService.java index d74434a6d2df..940942b40f7c 100644 --- a/src/main/java/de/tum/in/www1/artemis/service/connectors/aeolus/AeolusTemplateService.java +++ b/src/main/java/de/tum/in/www1/artemis/service/connectors/aeolus/AeolusTemplateService.java @@ -33,7 +33,7 @@ @Profile("aeolus | localci") public class AeolusTemplateService { - private final Logger LOGGER = LoggerFactory.getLogger(AeolusTemplateService.class); + private final Logger logger = LoggerFactory.getLogger(AeolusTemplateService.class); private final ProgrammingLanguageConfiguration programmingLanguageConfiguration; @@ -44,6 +44,25 @@ public class AeolusTemplateService { public AeolusTemplateService(ProgrammingLanguageConfiguration programmingLanguageConfiguration, ResourceLoaderService resourceLoaderService) { this.programmingLanguageConfiguration = programmingLanguageConfiguration; this.resourceLoaderService = resourceLoaderService; + // load all scripts into the cache + cacheOnBoot(); + } + + private void cacheOnBoot() { + var resources = this.resourceLoaderService.getResources(Path.of("templates", "aeolus")); + for (var resource : resources) { + try { + String filename = resource.getFilename(); + String directory = resource.getURL().getPath().split("templates/aeolus/")[1].split("/")[0]; + String uniqueKey = directory + "_" + filename; + byte[] fileContent = IOUtils.toByteArray(resource.getInputStream()); + String script = new String(fileContent, StandardCharsets.UTF_8); + templateCache.put(uniqueKey, readWindfile(script)); + } + catch (IOException e) { + logger.error("Failed to load windfile {}", resource.getFilename(), e); + } + } } /** @@ -118,7 +137,7 @@ public Windfile getDefaultWindfileFor(ProgrammingExercise exercise) { exercise.hasSequentialTestRuns(), exercise.isTestwiseCoverageEnabled()); } catch (IOException e) { - LOGGER.info("No windfile for the settings of exercise {}", exercise.getId(), e); + logger.info("No windfile for the settings of exercise {}", exercise.getId(), e); } return null; }