Skip to content

Commit

Permalink
RP-814 Apply cache to build list
Browse files Browse the repository at this point in the history
  • Loading branch information
QuyenLy87 committed May 2, 2024
1 parent d43f0fd commit 8e650e6
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 65 deletions.
3 changes: 2 additions & 1 deletion src/main/java/org/ihtsdo/buildcloud/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,8 @@ public SimpleCacheManager cacheManager() {
cacheManager.setCaches(Arrays.asList(
getCache("release-center-records"),
getCache("global-roles"),
getCache("code-system-roles")));
getCache("code-system-roles"),
getCache("build-records")));
return cacheManager;
}

Expand Down
46 changes: 46 additions & 0 deletions src/main/java/org/ihtsdo/buildcloud/core/dao/BuildDAOCache.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.ihtsdo.buildcloud.core.dao;

import org.ihtsdo.otf.dao.s3.S3Client;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import software.amazon.awssdk.services.s3.model.ListObjectsRequest;
import software.amazon.awssdk.services.s3.model.ListObjectsResponse;
import software.amazon.awssdk.services.s3.model.S3Object;

import java.util.ArrayList;
import java.util.List;

@Service
public class BuildDAOCache {

private static final Logger LOGGER = LoggerFactory.getLogger(BuildDAOCache.class);

@Cacheable(value = "build-records", key="#releaseCenterKey.concat('-').concat(#productKey)")
public List<S3Object> getAllS3ObjectKeysWithCache(final S3Client s3Client, String buildBucketName, String prefix, String releaseCenterKey, String productKey) {
return getS3Objects(s3Client, buildBucketName, prefix);
}

public List<S3Object> getAllS3ObjectKeysNoCache(final S3Client s3Client, String buildBucketName, String prefix) {
return getS3Objects(s3Client, buildBucketName, prefix);
}

private static List<S3Object> getS3Objects(S3Client s3Client, String buildBucketName, String prefix) {
LOGGER.debug("Reading S3Objects in {}, {} in batches.", buildBucketName, prefix);
ListObjectsRequest listObjectsRequest = ListObjectsRequest.builder().bucket(buildBucketName).prefix(prefix).maxKeys(10000).build();
List<S3Object> s3Objects = new ArrayList<>();
boolean done = false;
while (!done) {
ListObjectsResponse listObjectsResponse = s3Client.listObjects(listObjectsRequest);
s3Objects.addAll(listObjectsResponse.contents());
if (Boolean.TRUE.equals(listObjectsResponse.isTruncated())) {
String nextMarker = s3Objects.get(s3Objects.size() - 1).key();
listObjectsRequest = ListObjectsRequest.builder().bucket(buildBucketName).prefix(prefix).maxKeys(10000).marker(nextMarker).build();
} else {
done = true;
}
}
return s3Objects;
}
}
Loading

0 comments on commit 8e650e6

Please sign in to comment.