From: Julien Lancelot Date: Tue, 23 Dec 2014 09:40:47 +0000 (+0100) Subject: SONAR-5817 Fix max number of lines to 500000 X-Git-Tag: 5.0-RC4~18 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8dc596c217ced580c3c2f87bb70b984d54289251;p=sonarqube.git SONAR-5817 Fix max number of lines to 500000 --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineIndex.java b/server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineIndex.java index 7269ceb8777..f3c84bb650c 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineIndex.java +++ b/server/sonar-server/src/main/java/org/sonar/server/source/index/SourceLineIndex.java @@ -31,6 +31,8 @@ import java.util.List; public class SourceLineIndex implements ServerComponent { + private static final int MAX_RESULT = 500000; + private final EsClient esClient; public SourceLineIndex(EsClient esClient) { @@ -41,6 +43,8 @@ public class SourceLineIndex implements ServerComponent { * Get lines of code for file with UUID fileUuid with line numbers * between from and to (both inclusive). Line numbers * start at 1. + * The max number of returned lines will be 500000. + * * @param fileUuid the UUID of the file for which to get source code * @param from starting line; must be strictly positive * @param to ending line; must be greater than or equal to to @@ -49,15 +53,20 @@ public class SourceLineIndex implements ServerComponent { Preconditions.checkArgument(from > 0, "Minimum value for 'from' is 1"); Preconditions.checkArgument(to >= from, "'to' must be larger than or equal to 'from'"); List lines = Lists.newArrayList(); + int size = 1 + to - from; + if (size > MAX_RESULT) { + size = MAX_RESULT; + } + int toLimited = size + from - 1; for (SearchHit hit: esClient.prepareSearch(SourceLineIndexDefinition.INDEX) .setTypes(SourceLineIndexDefinition.TYPE) - .setSize(1 + to - from) + .setSize(size) .setQuery(QueryBuilders.boolQuery() .must(QueryBuilders.termQuery(SourceLineIndexDefinition.FIELD_FILE_UUID, fileUuid)) .must(QueryBuilders.rangeQuery(SourceLineIndexDefinition.FIELD_LINE) .gte(from) - .lte(to))) + .lte(toLimited))) .addSort(SourceLineIndexDefinition.FIELD_LINE, SortOrder.ASC) .get().getHits().getHits()) { lines.add(new SourceLineDoc(hit.sourceAsMap()));