Skip to content
Snippets Groups Projects

feat: Change loading cache pre-load

1 file
+ 14
9
Compare changes
  • Side-by-side
  • Inline
@@ -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<CveData> 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) {
Loading