]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-4301 Improve issues sort
authorJulien Lancelot <julien.lancelot@gmail.com>
Wed, 22 May 2013 15:30:54 +0000 (17:30 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Wed, 22 May 2013 15:30:54 +0000 (17:30 +0200)
sonar-core/src/main/java/org/sonar/core/issue/db/IssueDao.java
sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml
sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java
sonar-server/src/main/java/org/sonar/server/issue/DefaultIssueFinder.java
sonar-server/src/main/java/org/sonar/server/issue/IssuesFinderSort.java
sonar-server/src/main/webapp/WEB-INF/app/helpers/issues_helper.rb

index 9d0727892ab00f70511d26ecd06dad25ffc394c1..89043f3791c64e9352161a9ecbe243766ac25ca1 100644 (file)
@@ -138,7 +138,7 @@ public class IssueDao implements BatchComponent, ServerComponent {
   }
 
   @VisibleForTesting
-  Collection<IssueDto> selectByIds(Collection<Long> ids) {
+  List<IssueDto> selectByIds(Collection<Long> ids) {
     SqlSession session = mybatis.openSession();
     try {
       return selectByIds(ids, session);
@@ -147,7 +147,7 @@ public class IssueDao implements BatchComponent, ServerComponent {
     }
   }
 
-  public Collection<IssueDto> selectByIds(Collection<Long> ids, SqlSession session) {
+  public List<IssueDto> selectByIds(Collection<Long> ids, SqlSession session) {
     if (ids.isEmpty()) {
       return Collections.emptyList();
     }
index 52ae50afaa365e46af85ec2003bad1d9ca328acc..19aea4a64af7e8ca5da4628d488597833b3ea168 100644 (file)
     <include refid="selectQueryConditions"/>
   </select>
 
-  <select id="selectIssueAndProjectIds" parameterType="map" resultType="Issue">
+  <select id="selectIssueAndProjectIds" parameterType="map" resultType="Issue" fetchSize="500">
     select i.id, i.project_id as projectId
     <include refid="sortColumn"/>
     <include refid="selectQueryConditions"/>
index b27dd441564467d955cc32c19dd2c94a53dbe365..26a2cbd712307d08620cb242de9d40fa023a544f 100644 (file)
@@ -37,7 +37,7 @@ public class IssueQuery {
 
   public static final int DEFAULT_PAGE_INDEX = 1;
   public static final int DEFAULT_PAGE_SIZE = 100;
-  public static final int MAX_RESULTS = 5000;
+  public static final int MAX_RESULTS = 10000;
   public static final int MAX_PAGE_SIZE = 500;
   public static final int MAX_ISSUE_KEYS = 500;
 
index 3736a6e3f4990bcf6757989e2f9e583850c3c0a8..985bae3d4cf94b3d005027e82a781e0f572f89ec 100644 (file)
@@ -107,15 +107,15 @@ public class DefaultIssueFinder implements IssueFinder {
       List<IssueDto> authorizedIssues = issueDao.selectIssueAndProjectIds(query, rootProjectIds, sqlSession);
 
       // 3. Sort all authorized issues
-      Collection<IssueDto> authorizedSortedIssues = new IssuesFinderSort(authorizedIssues, query).sort();
+      List<IssueDto> authorizedSortedIssues = sort(authorizedIssues, query, authorizedIssues.size());
 
       // 4. Apply pagination
       Paging paging = Paging.create(query.pageSize(), query.pageIndex(), authorizedSortedIssues.size());
       Set<Long> pagedIssueIds = pagedIssueIds(authorizedSortedIssues, paging);
 
       // 5. Load issues and their related data (rules, components, projects, comments, action plans, ...) and sort then again
-      Collection<IssueDto> pagedIssues = issueDao.selectByIds(pagedIssueIds, sqlSession);
-      Collection<IssueDto> pagedSortedIssues = new IssuesFinderSort(pagedIssues, query).sort();
+      List<IssueDto> pagedIssues = issueDao.selectByIds(pagedIssueIds, sqlSession);
+      List<IssueDto> pagedSortedIssues = sort(pagedIssues, query, authorizedIssues.size());
 
       Map<String, DefaultIssue> issuesByKey = newHashMap();
       List<Issue> issues = newArrayList();
@@ -165,6 +165,13 @@ public class DefaultIssueFinder implements IssueFinder {
     }
   }
 
+  private List<IssueDto> sort(List<IssueDto> issues, IssueQuery query, int allIssuesSize){
+    if (allIssuesSize < query.maxResults()) {
+      return new IssuesFinderSort(issues, query).sort();
+    }
+    return issues;
+  }
+
   private Set<Long> pagedIssueIds(Collection<IssueDto> issues, Paging paging) {
     Set<Long> issueIds = Sets.newLinkedHashSet();
     int index = 0;
index 086365f974d46c37d2ff16368408765daafd104c..fae20ee7eb55ef0e65aff0c4f7384ff6a55a6e0d 100644 (file)
@@ -31,15 +31,15 @@ import java.util.List;
 
 class IssuesFinderSort {
 
-  private Collection<IssueDto> issues;
+  private List<IssueDto> issues;
   private IssueQuery query;
 
-  public IssuesFinderSort(Collection<IssueDto> issues, IssueQuery query) {
+  public IssuesFinderSort(List<IssueDto> issues, IssueQuery query) {
     this.issues = issues;
     this.query = query;
   }
 
-  public Collection<IssueDto> sort() {
+  public List<IssueDto> sort() {
     if (query.sort() != null) {
       IssueProcessor issueProcessor;
       switch (query.sort()) {
index fab4c9a0457f86a8b07dd93b1d1773c24753979c..413e03c6766d51ab340246c9b05d2769cff43923 100644 (file)
@@ -22,13 +22,12 @@ module IssuesHelper
   def column_html(filter, column_label, column_tooltip, sort)
     filter_sort = filter.criteria[:sort]
     filter_asc = filter.criteria[:asc] == 'true' ? true : false
-    if !filter.issues_result.maxResultsReached()
+    html = h(column_label)
+    unless filter.issues_result.maxResultsReached()
       html = link_to_function(h(column_label), "refreshList('#{escape_javascript sort}',#{!filter_asc}, #{filter.criteria[:page]||1})", :title => h(column_tooltip))
       if sort == filter_sort
         html << (filter_asc ? image_tag("asc12.png") : image_tag("desc12.png"))
       end
-    else
-      html = h(column_label)
     end
     html
   end