Skip to content

Commit 682c872

Browse files
authored
Merge pull request #253 from aodn/bugfix/7080-estimate-understate
Avoid understate on low record count
2 parents eeb30e8 + 39b5def commit 682c872

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

server/src/main/java/au/org/aodn/ogcapi/server/core/service/geoserver/wfs/DownloadWfsDataService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,19 @@ public BigInteger estimateDownloadSize(
120120
Object o = parser.parse(new StringReader(response.getBody()));
121121
if(o instanceof FeatureCollectionType hits) {
122122
BigInteger featureCount = hits.getNumberOfFeatures();
123+
// In case the records we have is smaller than our predefined SAMPLES_SIZE, we use smaller one.
124+
long sampleSize = featureCount.longValue() < SAMPLES_SIZE ? featureCount.longValue() : SAMPLES_SIZE;
123125

124126
log.debug("Total record hits {}", featureCount);
125127
// Now we need to do another query where we limited the record count to something small
126128
wfsRequestUrl = prepareWfsRequestUrl(
127-
uuid, startDate, endDate, multiPolygon, fields, layerName, outputFormat, SAMPLES_SIZE, false
129+
uuid, startDate, endDate, multiPolygon, fields, layerName, outputFormat, sampleSize, false
128130
);
129131
ResponseEntity<byte[]> bytes = restTemplate.exchange(wfsRequestUrl, HttpMethod.GET, pretendUserEntity, byte[].class);
130132
if(bytes.getStatusCode().is2xxSuccessful() && bytes.getBody() != null) {
131133
return featureCount
132134
.multiply(BigInteger.valueOf(bytes.getBody().length))
133-
.divide(BigInteger.valueOf(SAMPLES_SIZE));
135+
.divide(BigInteger.valueOf(sampleSize));
134136
}
135137
}
136138
else if(o instanceof ExceptionReportType report) {

0 commit comments

Comments
 (0)