From 2ec0ce9808ba9835c00caaaa2924a26ff1317509 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 16 May 2013 13:37:34 +0200 Subject: [PATCH] SONAR-3755 fix performance issue when loading transitions --- .../server/issue/InternalRubyIssueService.java | 8 ++++++-- .../java/org/sonar/server/issue/IssueService.java | 14 ++++++++++++-- .../WEB-INF/app/controllers/issue_controller.rb | 8 ++++---- .../app/views/{resource => issue}/_issue.html.erb | 2 +- .../WEB-INF/app/views/issue/_plan_form.html.erb | 1 + .../webapp/WEB-INF/app/views/issue/show.html.erb | 2 +- .../app/views/resource/_index_issues.html.erb | 2 +- .../app/views/shared/_source_issues.html.erb | 2 +- 8 files changed, 27 insertions(+), 12 deletions(-) rename sonar-server/src/main/webapp/WEB-INF/app/views/{resource => issue}/_issue.html.erb (97%) diff --git a/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java b/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java index a136bcf1c6d..d40ae9a6a37 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java @@ -66,7 +66,11 @@ public class InternalRubyIssueService implements ServerComponent { } public List listTransitions(String issueKey) { - return issueService.listTransitions(issueKey, UserSession.get()); + return issueService.listTransitions(issueKey); + } + + public List listTransitions(Issue issue) { + return issueService.listTransitions(issue); } public Issue doTransition(String issueKey, String transitionKey) { @@ -81,7 +85,7 @@ public class InternalRubyIssueService implements ServerComponent { return issueService.setSeverity(issueKey, severity, UserSession.get()); } - public Issue plan(String issueKey, String actionPlanKey) { + public Issue plan(String issueKey, @Nullable String actionPlanKey) { return issueService.plan(issueKey, actionPlanKey, UserSession.get()); } diff --git a/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java b/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java index 7cf04f2e0de..dd4340c6d7b 100644 --- a/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java +++ b/sonar-server/src/main/java/org/sonar/server/issue/IssueService.java @@ -32,7 +32,6 @@ import org.sonar.core.issue.workflow.Transition; import org.sonar.server.platform.UserSession; import javax.annotation.Nullable; - import java.util.Collections; import java.util.Comparator; import java.util.Date; @@ -60,7 +59,7 @@ public class IssueService implements ServerComponent { this.actionPlanService = actionPlanService; } - public List listTransitions(String issueKey, UserSession userSession) { + public List listTransitions(String issueKey) { DefaultIssue issue = loadIssue(issueKey); List transitions = workflow.outTransitions(issue); Collections.sort(transitions, new Comparator() { @@ -72,6 +71,17 @@ public class IssueService implements ServerComponent { return transitions; } + public List listTransitions(Issue issue) { + List transitions = workflow.outTransitions(issue); + Collections.sort(transitions, new Comparator() { + @Override + public int compare(Transition transition, Transition transition2) { + return transition.key().compareTo(transition2.key()); + } + }); + return transitions; + } + public Issue doTransition(String issueKey, String transition, UserSession userSession) { verifyLoggedIn(userSession); DefaultIssue issue = loadIssue(issueKey); diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/issue_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/issue_controller.rb index a5ad2fac4b4..e0ff09bcc90 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/issue_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/issue_controller.rb @@ -27,7 +27,7 @@ class IssueController < ApplicationController @issue_results = Api.issues.find(params[:id]) if request.xhr? - render :partial => 'resource/issue', :locals => {:issue => @issue_results.issues.get(0)} + render :partial => 'issue/issue', :locals => {:issue => @issue_results.issues.get(0)} else params[:layout] = 'false' render :action => 'show' @@ -67,7 +67,7 @@ class IssueController < ApplicationController end @issue_results = Api.issues.find(issue_key) - render :partial => 'resource/issue', :locals => {:issue => @issue_results.issues.get(0)} + render :partial => 'issue/issue', :locals => {:issue => @issue_results.issues.get(0)} end # form to edit comment @@ -88,7 +88,7 @@ class IssueController < ApplicationController comment = Internal.issues.editComment(params[:key], text) @issue_results = Api.issues.find(comment.issueKey) - render :partial => 'resource/issue', :locals => {:issue => @issue_results.issues.get(0)} + render :partial => 'issue/issue', :locals => {:issue => @issue_results.issues.get(0)} end # modal window to delete comment @@ -106,7 +106,7 @@ class IssueController < ApplicationController comment = Internal.issues.deleteComment(params[:id]) @issue_results = Api.issues.find(comment.issueKey) - render :partial => 'resource/issue', :locals => {:issue => @issue_results.issues.get(0)} + render :partial => 'issue/issue', :locals => {:issue => @issue_results.issues.get(0)} end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_issue.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb similarity index 97% rename from sonar-server/src/main/webapp/WEB-INF/app/views/resource/_issue.html.erb rename to sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb index 416798629f4..7a12817dcee 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_issue.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb @@ -82,7 +82,7 @@ <% end %> - <% Internal.issues.listTransitions(issue.key).each do |transition| %> + <% Internal.issues.listTransitions(issue).each do |transition| %> <%= message("issue.transition.#{transition.key}") -%> <% end %> diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_plan_form.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_plan_form.html.erb index 4d3bec0e7a6..244f36b4b29 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_plan_form.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_plan_form.html.erb @@ -12,6 +12,7 @@