RED-4928: Removed caching since it is currently not needed.
Removed caching since it is currently not needed (no cache hits as intended), and would need to be implemented as a distributed cache.
This commit is contained in:
parent
ba6148209d
commit
66b1f42400
@ -9,17 +9,13 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import com.github.benmanes.caffeine.cache.LoadingCache;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.entity.dossier.DossierEntity;
|
||||
import com.iqser.red.service.persistence.management.v1.processor.exception.InternalServerErrorException;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.license.LicenseReport;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.license.LicenseReportRequest;
|
||||
import com.iqser.red.service.persistence.service.v1.api.model.license.ReportData;
|
||||
@ -38,12 +34,6 @@ public class LicenseReportService {
|
||||
private final FileStatusService fileStatusService;
|
||||
private final DossierService dossierService;
|
||||
|
||||
private final LoadingCache<LicenseReportRequest, CachedReportData> cachedReports = Caffeine.newBuilder()
|
||||
.maximumSize(1_000)
|
||||
.expireAfterAccess(5, TimeUnit.MINUTES)
|
||||
.build(this::loadReport);
|
||||
|
||||
|
||||
public LicenseReport getLicenseReport(LicenseReportRequest licenseReportRequest, int offset, int limit) {
|
||||
|
||||
log.info("Generating licence-report");
|
||||
@ -56,23 +46,21 @@ public class LicenseReportService {
|
||||
if (StringUtils.isEmpty(licenseReportRequest.getRequestId())) {
|
||||
licenseReportRequest.setRequestId(UUID.randomUUID().toString());
|
||||
}
|
||||
CachedReportData cachedReportData = cachedReports.get(licenseReportRequest);
|
||||
if (cachedReportData == null) {
|
||||
throw new InternalServerErrorException("Report not loaded");
|
||||
}
|
||||
|
||||
DetailedReportData detailedReportData = loadDetailedReportData(licenseReportRequest);
|
||||
|
||||
LicenseReport licenseReport = new LicenseReport();
|
||||
licenseReport.setNumberOfAnalyzedPages(cachedReportData.getTotalPagesAnalyzed());
|
||||
licenseReport.setNumberOfAnalyzedFiles(cachedReportData.getData().size());
|
||||
licenseReport.setNumberOfOcrFiles((int) cachedReportData.getData().stream().filter(reportData -> reportData.getNumberOfOcrPages() > 0).count());
|
||||
licenseReport.setNumberOfOcrPages(cachedReportData.getTotalOcrPages());
|
||||
licenseReport.setNumberOfDossiers(cachedReportData.getNumberOfDossiers());
|
||||
licenseReport.setNumberOfAnalyses(cachedReportData.getTotalNumberOfAnalyses());
|
||||
licenseReport.setData(cachedReportData.getData().subList(offset, Math.min(offset + limit, cachedReportData.getData().size())));
|
||||
licenseReport.setNumberOfAnalyzedPages(detailedReportData.getTotalPagesAnalyzed());
|
||||
licenseReport.setNumberOfAnalyzedFiles(detailedReportData.getData().size());
|
||||
licenseReport.setNumberOfOcrFiles((int) detailedReportData.getData().stream().filter(reportData -> reportData.getNumberOfOcrPages() > 0).count());
|
||||
licenseReport.setNumberOfOcrPages(detailedReportData.getTotalOcrPages());
|
||||
licenseReport.setNumberOfDossiers(detailedReportData.getNumberOfDossiers());
|
||||
licenseReport.setNumberOfAnalyses(detailedReportData.getTotalNumberOfAnalyses());
|
||||
licenseReport.setData(detailedReportData.getData().subList(offset, Math.min(offset + limit, detailedReportData.getData().size())));
|
||||
licenseReport.setOffset(offset);
|
||||
licenseReport.setLimit(limit);
|
||||
licenseReport.setStartDate(cachedReportData.getStartDate());
|
||||
licenseReport.setEndDate(cachedReportData.getEndDate());
|
||||
licenseReport.setStartDate(detailedReportData.getStartDate());
|
||||
licenseReport.setEndDate(detailedReportData.getEndDate());
|
||||
licenseReport.setRequestId(licenseReportRequest.getRequestId());
|
||||
|
||||
if (start != null) {
|
||||
@ -84,7 +72,7 @@ public class LicenseReportService {
|
||||
}
|
||||
|
||||
|
||||
private CachedReportData loadReport(LicenseReportRequest licenseReportRequest) {
|
||||
private DetailedReportData loadDetailedReportData(LicenseReportRequest licenseReportRequest) {
|
||||
|
||||
log.debug("No licence-report found in cache, generating new report");
|
||||
Instant start = null;
|
||||
@ -99,7 +87,7 @@ public class LicenseReportService {
|
||||
dossierIds = new HashSet<>(licenseReportRequest.getDossierIds());
|
||||
}
|
||||
|
||||
var result = new CachedReportData(new LinkedList<>(), dossierIds.size(), 0, 0, 0, licenseReportRequest.getStartDate(), licenseReportRequest.getEndDate());
|
||||
var result = new DetailedReportData(new LinkedList<>(), dossierIds.size(), 0, 0, 0, licenseReportRequest.getStartDate(), licenseReportRequest.getEndDate());
|
||||
|
||||
fileStatusService.getStatusesForDossiersAndTimePeriod( //
|
||||
dossierIds, //
|
||||
@ -131,9 +119,12 @@ public class LicenseReportService {
|
||||
}
|
||||
|
||||
|
||||
// This was also used to cache results so that subsequent pagination works faster.
|
||||
// Currently, pagination is unused, and it is unclear, if caching is needed.
|
||||
// This intermediate object may be re-used for caching and pagination, if needed.
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
private static class CachedReportData {
|
||||
private static class DetailedReportData {
|
||||
|
||||
List<ReportData> data;
|
||||
int numberOfDossiers;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user