From 0aab6fc52cc255dbdc1e3e8f9975f45199cb2bbf Mon Sep 17 00:00:00 2001 From: Zachary Sabourin Date: Tue, 27 Sep 2022 11:53:07 -0400 Subject: [PATCH] feat: Change loading cache pre-load --- .../impl/DefaultCveCachingService.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/eclipsefoundation/cve/service/impl/DefaultCveCachingService.java b/src/main/java/org/eclipsefoundation/cve/service/impl/DefaultCveCachingService.java index 3161396..a025dfc 100644 --- a/src/main/java/org/eclipsefoundation/cve/service/impl/DefaultCveCachingService.java +++ b/src/main/java/org/eclipsefoundation/cve/service/impl/DefaultCveCachingService.java @@ -73,19 +73,19 @@ public class DefaultCveCachingService implements CveCachingService { */ @PostConstruct public void init() { - this.githubLoadingCache = Caffeine + this.gitlabLoadingCache = Caffeine .newBuilder() .executor(executor) - .maximumSize(70) + .maximumSize(10) .refreshAfterWrite(Duration.ofMinutes(60)) - .buildAsync(this::loadGithubData); + .buildAsync(this::loadGitlabData); - this.gitlabLoadingCache = Caffeine + this.githubLoadingCache = Caffeine .newBuilder() .executor(executor) - .maximumSize(10) + .maximumSize(100) .refreshAfterWrite(Duration.ofMinutes(60)) - .buildAsync(this::loadGitlabData); + .buildAsync(this::loadGithubData); preLoadCaches(); } @@ -104,7 +104,7 @@ public class DefaultCveCachingService implements CveCachingService { try { return githubLoadingCache.get(key).get(); } catch (InterruptedException | ExecutionException e) { - throw new RuntimeException(String.format("Could not get cached GH CVE data for id: {}", key), e); + throw new RuntimeException(String.format("Could not get cached GH CVE data for id: %s", key), e); } } @@ -112,9 +112,9 @@ public class DefaultCveCachingService implements CveCachingService { * Pre-loads both the GH and GL loading caches. */ private void preLoadCaches() { - loadGitlabData("all").parallelStream().forEach(cve -> { + getLoadedGitlabData("all").stream().forEach(cve -> { if (!cve.getId().isEmpty()) { - loadGithubData(cve.getId()); + getLoadedGithubData(cve.getId()); } }); } @@ -126,12 +126,15 @@ public class DefaultCveCachingService implements CveCachingService { */ private List loadGitlabData(String key) { try { + LOGGER.info("Loading GL data for key: {}", key); + GitlabRequestParams params = GitlabRequestParams.builder() .setId(configProperties.get("project-id")) .setFilePath(configProperties.get("file-path")) .setRef(configProperties.get("ref")) .setPrivateToken(configProperties.get("token")) .build(); + return om.readerForListOf(CveData.class).readValue(gitlabApi.getCveFile(params)); } catch (Exception e) { throw new RuntimeException("Could not fetch CVE data from GitLab", e); @@ -153,6 +156,8 @@ public class DefaultCveCachingService implements CveCachingService { return null; } + LOGGER.info("Loading GH data for key: {}", key); + return om.readerFor(CveProjectData.class) .readValue(githubApi.getCveDetails(matcher.group(1), matcher.group(2), key)); } catch (Exception e) { -- GitLab