summaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-04-23 14:35:22 +0200
committerJulien Lancelot <julien.lancelot@gmail.com>2013-04-23 14:35:22 +0200
commita4061d9dc28fd34f376636dfa35d805052430a64 (patch)
tree15ef0c28737882755a297ad1e352c2a059b6567d /sonar-server
parent270a0e56519dfd6f4fc6104f09a70be54a7e6d14 (diff)
downloadsonarqube-a4061d9dc28fd34f376636dfa35d805052430a64.tar.gz
sonarqube-a4061d9dc28fd34f376636dfa35d805052430a64.zip
SONAR-3755 Issue finder optimization
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/issue/ServerIssueFinder.java12
-rw-r--r--sonar-server/src/test/java/org/sonar/server/issue/ServerIssueFinderTest.java26
2 files changed, 34 insertions, 4 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/issue/ServerIssueFinder.java b/sonar-server/src/main/java/org/sonar/server/issue/ServerIssueFinder.java
index f406f4867b7..b5e52df61ff 100644
--- a/sonar-server/src/main/java/org/sonar/server/issue/ServerIssueFinder.java
+++ b/sonar-server/src/main/java/org/sonar/server/issue/ServerIssueFinder.java
@@ -86,7 +86,11 @@ public class ServerIssueFinder implements IssueFinder {
ruleIds.add(dto.getRuleId());
}
}
- return new DefaultResults(issues, getRulesByIssue(issues, ruleIds), getComponentsByIssue(issues, componentIds));
+ if (!issues.isEmpty()) {
+ return new DefaultResults(issues, getRulesByIssue(issues, ruleIds), getComponentsByIssue(issues, componentIds));
+ } else {
+ return new DefaultResults(issues);
+ }
} finally {
MyBatis.closeQuietly(sqlSession);
}
@@ -144,6 +148,12 @@ public class ServerIssueFinder implements IssueFinder {
this.componentsByIssue = componentsByIssue;
}
+ DefaultResults(List<Issue> issues) {
+ this.issues = issues;
+ this.rulesByIssue = newHashMap();
+ this.componentsByIssue = newHashMap();
+ }
+
@Override
public List<Issue> issues() {
return issues;
diff --git a/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueFinderTest.java b/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueFinderTest.java
index d3bf37c085e..7d71aa1e8f2 100644
--- a/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueFinderTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/issue/ServerIssueFinderTest.java
@@ -38,13 +38,18 @@ import org.sonar.core.resource.ResourceDao;
import org.sonar.core.rule.DefaultRuleFinder;
import org.sonar.core.user.AuthorizationDao;
+import java.util.Collections;
import java.util.List;
import static com.google.common.collect.Lists.newArrayList;
import static org.fest.assertions.Assertions.assertThat;
-import static org.mockito.Matchers.*;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyCollection;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anySet;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.*;
public class ServerIssueFinderTest {
@@ -148,6 +153,21 @@ public class ServerIssueFinderTest {
assertThat(results.components()).hasSize(1);
}
+ @Test
+ public void should_get_empty_rule_and_component_from_result_when_no_issue() {
+ grantAccessRights();
+ IssueQuery issueQuery = mock(IssueQuery.class);
+ when(issueDao.select(eq(issueQuery), any(SqlSession.class))).thenReturn(Collections.<IssueDto>emptyList());
+
+ IssueFinder.Results results = finder.find(issueQuery, null, UserRole.USER);
+ assertThat(results.issues()).isEmpty();
+ assertThat(results.rules()).isEmpty();
+ assertThat(results.components()).isEmpty();
+
+ verifyZeroInteractions(ruleFinder);
+ verifyZeroInteractions(resourceDao);
+ }
+
private void grantAccessRights() {
when(authorizationDao.keepAuthorizedComponentIds(anySet(), anyInt(), anyString(), any(SqlSession.class)))
.thenAnswer(new Answer<Object>() {