From c9c8fa20425f48628e05e1588c3b2549846721d3 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 22 May 2013 17:30:54 +0200 Subject: [PATCH] SONAR-4301 Improve issues sort --- .../main/java/org/sonar/core/issue/db/IssueDao.java | 4 ++-- .../org/sonar/core/issue/db/IssueMapper.xml | 2 +- .../main/java/org/sonar/api/issue/IssueQuery.java | 2 +- .../org/sonar/server/issue/DefaultIssueFinder.java | 13 ++++++++++--- .../org/sonar/server/issue/IssuesFinderSort.java | 6 +++--- .../webapp/WEB-INF/app/helpers/issues_helper.rb | 5 ++--- 6 files changed, 19 insertions(+), 13 deletions(-) diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDao.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDao.java index 9d0727892ab..89043f3791c 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDao.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueDao.java @@ -138,7 +138,7 @@ public class IssueDao implements BatchComponent, ServerComponent { } @VisibleForTesting - Collection selectByIds(Collection ids) { + List selectByIds(Collection ids) { SqlSession session = mybatis.openSession(); try { return selectByIds(ids, session); @@ -147,7 +147,7 @@ public class IssueDao implements BatchComponent, ServerComponent { } } - public Collection selectByIds(Collection ids, SqlSession session) { + public List selectByIds(Collection ids, SqlSession session) { if (ids.isEmpty()) { return Collections.emptyList(); } diff --git a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml index 52ae50afaa3..19aea4a64af 100644 --- a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml @@ -151,7 +151,7 @@ - select i.id, i.project_id as projectId diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java b/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java index b27dd441564..26a2cbd7123 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/issue/IssueQuery.java @@ -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; 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 3736a6e3f49..985bae3d4cf 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 @@ -107,15 +107,15 @@ public class DefaultIssueFinder implements IssueFinder { List authorizedIssues = issueDao.selectIssueAndProjectIds(query, rootProjectIds, sqlSession); // 3. Sort all authorized issues - Collection authorizedSortedIssues = new IssuesFinderSort(authorizedIssues, query).sort(); + List authorizedSortedIssues = sort(authorizedIssues, query, authorizedIssues.size()); // 4. Apply pagination Paging paging = Paging.create(query.pageSize(), query.pageIndex(), authorizedSortedIssues.size()); Set pagedIssueIds = pagedIssueIds(authorizedSortedIssues, paging); // 5. Load issues and their related data (rules, components, projects, comments, action plans, ...) and sort then again - Collection pagedIssues = issueDao.selectByIds(pagedIssueIds, sqlSession); - Collection pagedSortedIssues = new IssuesFinderSort(pagedIssues, query).sort(); + List pagedIssues = issueDao.selectByIds(pagedIssueIds, sqlSession); + List pagedSortedIssues = sort(pagedIssues, query, authorizedIssues.size()); Map issuesByKey = newHashMap(); List issues = newArrayList(); @@ -165,6 +165,13 @@ public class DefaultIssueFinder implements IssueFinder { } } + private List sort(List issues, IssueQuery query, int allIssuesSize){ + if (allIssuesSize < query.maxResults()) { + return new IssuesFinderSort(issues, query).sort(); + } + return issues; + } + private Set pagedIssueIds(Collection issues, Paging paging) { Set issueIds = Sets.newLinkedHashSet(); int index = 0; diff --git a/sonar-server/src/main/java/org/sonar/server/issue/IssuesFinderSort.java b/sonar-server/src/main/java/org/sonar/server/issue/IssuesFinderSort.java index 086365f974d..fae20ee7eb5 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/IssuesFinderSort.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/IssuesFinderSort.java @@ -31,15 +31,15 @@ import java.util.List; class IssuesFinderSort { - private Collection issues; + private List issues; private IssueQuery query; - public IssuesFinderSort(Collection issues, IssueQuery query) { + public IssuesFinderSort(List issues, IssueQuery query) { this.issues = issues; this.query = query; } - public Collection sort() { + public List sort() { if (query.sort() != null) { IssueProcessor issueProcessor; switch (query.sort()) { diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/issues_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/issues_helper.rb index fab4c9a0457..413e03c6766 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/issues_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/issues_helper.rb @@ -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 -- 2.39.5