From: Julien Lancelot Date: Wed, 30 Aug 2017 09:41:24 +0000 (+0200) Subject: SONAR-9616 Add project uuid routing when searching branch stats X-Git-Tag: 6.6-RC1~380^2~33 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=208d1e47d12f0fc58e22c1b97cd66d2d4fe0c4dd;p=sonarqube.git SONAR-9616 Add project uuid routing when searching branch stats --- diff --git a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java index 78a7dc1a53c..107f49b3a8a 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java +++ b/server/sonar-server/src/main/java/org/sonar/server/issue/index/IssueIndex.java @@ -707,12 +707,13 @@ public class IssueIndex { }).collect(MoreCollectors.toList(projectUuids.size())); } - public List searchBranchStatistics(List branchUuids) { + public List searchBranchStatistics(String projectUuid, List branchUuids) { if (branchUuids.isEmpty()) { return Collections.emptyList(); } SearchRequestBuilder request = client.prepareSearch(IssueIndexDefinition.INDEX_TYPE_ISSUE) + .setRouting(projectUuid) .setQuery( boolQuery() .must(termsQuery(IssueIndexDefinition.FIELD_ISSUE_BRANCH_UUID, branchUuids)) diff --git a/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ListAction.java b/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ListAction.java index fd176f09b8a..aeae39e6a64 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ListAction.java +++ b/server/sonar-server/src/main/java/org/sonar/server/projectbranch/ws/ListAction.java @@ -106,7 +106,7 @@ public class ListAction implements BranchWsAction { Map qualityGateMeasuresByComponentUuids = dbClient.measureDao() .selectByComponentsAndMetrics(dbSession, branches.stream().map(BranchDto::getUuid).collect(toList()), singletonList(qualityGateMetric.getId())) .stream().collect(uniqueIndex(MeasureDto::getComponentUuid)); - Map branchStatisticsByBranchUuid = issueIndex.searchBranchStatistics(branches.stream() + Map branchStatisticsByBranchUuid = issueIndex.searchBranchStatistics(project.uuid(), branches.stream() .filter(b -> b.getBranchType().equals(SHORT)) .map(BranchDto::getUuid).collect(toList())) .stream().collect(uniqueIndex(BranchStatistics::getBranchUuid, Function.identity())); diff --git a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java index 939a8181059..f11d9ab4c2b 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/issue/index/IssueIndexTest.java @@ -1311,7 +1311,7 @@ public class IssueIndexTest { newDoc(branch1).setType(BUG), newDoc(branch1).setType(VULNERABILITY), newDoc(branch1).setType(CODE_SMELL), newDoc(branch3).setType(CODE_SMELL), newDoc(branch3).setType(CODE_SMELL), newDoc(fileOnBranch3).setType(CODE_SMELL)); - List branchStatistics = underTest.searchBranchStatistics(asList(branch1.uuid(), branch2.uuid(), branch3.uuid())); + List branchStatistics = underTest.searchBranchStatistics(project.uuid(), asList(branch1.uuid(), branch2.uuid(), branch3.uuid())); assertThat(branchStatistics).extracting(BranchStatistics::getBranchUuid, BranchStatistics::getBugs, BranchStatistics::getVulnerabilities, BranchStatistics::getCodeSmells) .containsExactlyInAnyOrder( @@ -1331,7 +1331,7 @@ public class IssueIndexTest { branchUuids.add(branch.uuid()); }); - List branchStatistics = underTest.searchBranchStatistics(branchUuids); + List branchStatistics = underTest.searchBranchStatistics(project.uuid(), branchUuids); assertThat(branchStatistics) .extracting(BranchStatistics::getBranchUuid, BranchStatistics::getBugs, BranchStatistics::getVulnerabilities, BranchStatistics::getCodeSmells) @@ -1341,8 +1341,10 @@ public class IssueIndexTest { @Test public void searchBranchStatistics_on_empty_list() { - assertThat(underTest.searchBranchStatistics(emptyList())).isEmpty(); - assertThat(underTest.searchBranchStatistics(singletonList("unknown"))).isEmpty(); + ComponentDto project = db.components().insertMainBranch(); + + assertThat(underTest.searchBranchStatistics(project.uuid(), emptyList())).isEmpty(); + assertThat(underTest.searchBranchStatistics(project.uuid(), singletonList("unknown"))).isEmpty(); } private void addIssues(ComponentDto branch, int bugs, int vulnerabilities, int codeSmelles) {