aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-server
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@gmail.com>2013-05-24 13:59:47 +0200
committerJulien Lancelot <julien.lancelot@gmail.com>2013-05-24 13:59:47 +0200
commit9b54697acbceb0d1282398181901465c76f4af15 (patch)
tree890b824ada58d7377fb693996d22830cf3fcb15e /sonar-server
parent38c705b94e1cd8e5781c1d0ce025a67922a22d0d (diff)
downloadsonarqube-9b54697acbceb0d1282398181901465c76f4af15.tar.gz
sonarqube-9b54697acbceb0d1282398181901465c76f4af15.zip
SONAR-4301 Improve the issues search in order to select only project authorized for current user and limit the result directly in the SQL
Diffstat (limited to 'sonar-server')
-rw-r--r--sonar-server/src/main/java/org/sonar/server/issue/DefaultIssueFinder.java6
-rw-r--r--sonar-server/src/test/java/org/sonar/server/issue/DefaultIssueFinderTest.java7
2 files changed, 6 insertions, 7 deletions
diff --git a/sonar-server/src/main/java/org/sonar/server/issue/DefaultIssueFinder.java b/sonar-server/src/main/java/org/sonar/server/issue/DefaultIssueFinder.java
index eb8d42731a3..b95d56f7a45 100644
--- a/sonar-server/src/main/java/org/sonar/server/issue/DefaultIssueFinder.java
+++ b/sonar-server/src/main/java/org/sonar/server/issue/DefaultIssueFinder.java
@@ -97,13 +97,11 @@ public class DefaultIssueFinder implements IssueFinder {
LOG.debug("IssueQuery : {}", query);
SqlSession sqlSession = myBatis.openSession();
try {
- DefaultIssueQueryResult defaultIssueQueryResult = new DefaultIssueQueryResult();
-
// 1. Select all authorized root project ids for the user
Collection<Integer> rootProjectIds = authorizationDao.selectAuthorizedRootProjectsIds(UserSession.get().userId(), query.requiredRole(), sqlSession);
// 2. Select the authorized ids of all the issues that match the query
- List<IssueDto> authorizedIssues = issueDao.selectIssueAndProjectIds(query, defaultIssueQueryResult, rootProjectIds, sqlSession);
+ List<IssueDto> authorizedIssues = issueDao.selectIssueAndProjectIds(query, rootProjectIds, sqlSession);
// 3. Sort all authorized issues
List<IssueDto> authorizedSortedIssues = sort(authorizedIssues, query, authorizedIssues.size());
@@ -147,6 +145,8 @@ public class DefaultIssueFinder implements IssueFinder {
}
}
+ DefaultIssueQueryResult defaultIssueQueryResult = new DefaultIssueQueryResult();
+ defaultIssueQueryResult.setMaxResultsReached(authorizedIssues.size() == query.maxResults());
defaultIssueQueryResult.setIssues(issues)
.addRules(findRules(ruleIds))
.addComponents(findComponents(componentIds))
diff --git a/sonar-server/src/test/java/org/sonar/server/issue/DefaultIssueFinderTest.java b/sonar-server/src/test/java/org/sonar/server/issue/DefaultIssueFinderTest.java
index 15908508a8a..fd0fd24063e 100644
--- a/sonar-server/src/test/java/org/sonar/server/issue/DefaultIssueFinderTest.java
+++ b/sonar-server/src/test/java/org/sonar/server/issue/DefaultIssueFinderTest.java
@@ -30,7 +30,6 @@ import org.sonar.api.rules.Rule;
import org.sonar.api.user.UserFinder;
import org.sonar.core.component.ComponentDto;
import org.sonar.core.issue.DefaultActionPlan;
-import org.sonar.core.issue.DefaultIssueQueryResult;
import org.sonar.core.issue.db.IssueChangeDao;
import org.sonar.core.issue.db.IssueDao;
import org.sonar.core.issue.db.IssueDto;
@@ -84,7 +83,7 @@ public class DefaultIssueFinderTest {
when(issueDao.selectByIds(anyCollection(), any(SqlSession.class))).thenReturn(dtoList);
IssueQueryResult results = finder.find(query);
- verify(issueDao).selectIssueAndProjectIds(eq(query), any(DefaultIssueQueryResult.class), eq(newHashSet(100)), any(SqlSession.class));
+ verify(issueDao).selectIssueAndProjectIds(eq(query), eq(newHashSet(100)), any(SqlSession.class));
assertThat(results.issues()).hasSize(2);
Issue issue = results.issues().iterator().next();
@@ -112,7 +111,7 @@ public class DefaultIssueFinderTest {
.setRuleKey_unit_test_only("squid", "AvoidCycle")
.setStatus("OPEN").setResolution("OPEN");
List<IssueDto> dtoList = newArrayList(issue1, issue2);
- when(issueDao.selectIssueAndProjectIds(eq(query), any(DefaultIssueQueryResult.class), eq(newHashSet(100)), any(SqlSession.class))).thenReturn(dtoList);
+ when(issueDao.selectIssueAndProjectIds(eq(query), eq(newHashSet(100)), any(SqlSession.class))).thenReturn(dtoList);
when(issueDao.selectByIds(anyCollection(), any(SqlSession.class))).thenReturn(dtoList);
IssueQueryResult results = finder.find(query);
@@ -253,7 +252,7 @@ public class DefaultIssueFinderTest {
public void should_get_empty_result_when_no_issue() {
grantAccessRights();
IssueQuery query = IssueQuery.builder().build();
- when(issueDao.selectIssueAndProjectIds(eq(query), any(DefaultIssueQueryResult.class), anyCollection(), any(SqlSession.class))).thenReturn(Collections.<IssueDto>emptyList());
+ when(issueDao.selectIssueAndProjectIds(eq(query), anyCollection(), any(SqlSession.class))).thenReturn(Collections.<IssueDto>emptyList());
when(issueDao.selectByIds(anyCollection(), any(SqlSession.class))).thenReturn(Collections.<IssueDto>emptyList());
IssueQueryResult results = finder.find(query);