From: Simon Brandhof Date: Thu, 16 May 2013 11:37:34 +0000 (+0200) Subject: SONAR-3755 fix performance issue when loading transitions X-Git-Tag: 3.6~354 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=2ec0ce9808ba9835c00caaaa2924a26ff1317509;p=sonarqube.git SONAR-3755 fix performance issue when loading transitions --- 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/issue/_issue.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb new file mode 100644 index 00000000000..7a12817dcee --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb @@ -0,0 +1,96 @@ +
+
+ +   + + <% rule_name = Internal.rules.ruleL10nName(@issue_results.rule(issue)) %> + <%= h rule_name -%> + +   + <%= image_tag 'sep12.png' -%> +   + + <% + created_at = Api::Utils.java_to_ruby_datetime(issue.creationDate()) + updated_at = Api::Utils.java_to_ruby_datetime(issue.updateDate()) + dates_title = "Created at #{l created_at} and updated at #{l updated_at}" + %> + <%= distance_of_time_in_words_to_now(created_at) -%> +   + <% + if issue.resolution + %> + <%= image_tag 'sep12.png' -%> +   + <%= message("issue.resolution.#{issue.resolution}") -%> +   + <% end %> + <% + if issue.assignee + %> + <%= image_tag 'sep12.png' -%> +   + <%= message('assigned_to') -%> <%= h(@issue_results.user(issue.assignee).name) -%> +   + <% end %> + <% + if issue.actionPlanKey() + %> + <%= image_tag 'sep12.png' -%> +   + <%= message('issue.planned_for_x', :params => h(@issue_results.actionPlan(issue).name())) if @issue_results.actionPlan(issue) -%> +   + <% end %> + +
+ + <% unless issue.message.blank? %> +
+ <%= Api::Utils.split_newlines(h(issue.message)).join('
') -%> +
+ <% end %> + + <% + issue.comments.each do |comment| + comment_html_id = "comment-#{comment.key}-#{rand(100)}" + %> +
+

+ <%= image_tag('reviews/comment.png') -%>  <%= @issue_results.user(comment.userLogin()).name() -%> + (<%= distance_of_time_in_words_to_now(Api::Utils.java_to_ruby_datetime(comment.createdAt)) -%>) + <% if current_user && current_user.login==comment.userLogin %> +   + <%= image_tag 'sep12.png' -%> +   + <%= message('edit') -%> + <%= message('delete') -%> + <% end %> +

+ <%= Internal.text.markdownToHtml(comment.markdownText) -%> +
+ <% end %> + + <% if current_user %> +
+ <%= message('issue.comment.formlink') -%> + <% unless issue.resolution %> + + <%= message('issue.assign.formlink') -%> + <% if issue.assignee!=current_user.login %> + [<%= message('issue.assign.to_me') -%>] + <% end %> + + <% end %> + + <% Internal.issues.listTransitions(issue).each do |transition| %> + <%= message("issue.transition.#{transition.key}") -%> + <% end %> + + <% unless issue.resolution %> + <%= message("issue.set_severity") -%> + <%= message("issue.do_plan") -%> + <% end %> +
+ + <% end %> +
\ No newline at end of file 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 @@