]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3755 fix performance issue when loading transitions
authorSimon Brandhof <simon.brandhof@gmail.com>
Thu, 16 May 2013 11:37:34 +0000 (13:37 +0200)
committerSimon Brandhof <simon.brandhof@gmail.com>
Thu, 16 May 2013 11:37:59 +0000 (13:37 +0200)
sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java
sonar-server/src/main/java/org/sonar/server/issue/IssueService.java
sonar-server/src/main/webapp/WEB-INF/app/controllers/issue_controller.rb
sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb [new file with mode: 0644]
sonar-server/src/main/webapp/WEB-INF/app/views/issue/_plan_form.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/issue/show.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/resource/_index_issues.html.erb
sonar-server/src/main/webapp/WEB-INF/app/views/resource/_issue.html.erb [deleted file]
sonar-server/src/main/webapp/WEB-INF/app/views/shared/_source_issues.html.erb

index a136bcf1c6d4c263ee5cf3d61d657b81c1cf6935..d40ae9a6a374ed99ebf70f7b147ecbc1f2e19647 100644 (file)
@@ -66,7 +66,11 @@ public class InternalRubyIssueService implements ServerComponent {
   }
 
   public List<Transition> listTransitions(String issueKey) {
-    return issueService.listTransitions(issueKey, UserSession.get());
+    return issueService.listTransitions(issueKey);
+  }
+
+  public List<Transition> 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());
   }
 
index 7cf04f2e0de01614eb84bcfaf792772d96885273..dd4340c6d7bb1d1a47ebcf53e1b30a25dc34cc15 100644 (file)
@@ -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<Transition> listTransitions(String issueKey, UserSession userSession) {
+  public List<Transition> listTransitions(String issueKey) {
     DefaultIssue issue = loadIssue(issueKey);
     List<Transition> transitions = workflow.outTransitions(issue);
     Collections.sort(transitions, new Comparator<Transition>() {
@@ -72,6 +71,17 @@ public class IssueService implements ServerComponent {
     return transitions;
   }
 
+  public List<Transition> listTransitions(Issue issue) {
+    List<Transition> transitions = workflow.outTransitions(issue);
+    Collections.sort(transitions, new Comparator<Transition>() {
+      @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);
index a5ad2fac4b45f168e686e6c50bff4ccbc7ae0fe7..e0ff09bcc90df547aab5a05ce31745cf09500710 100644 (file)
@@ -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 (file)
index 0000000..7a12817
--- /dev/null
@@ -0,0 +1,96 @@
+<div class="code-issue" data-issue-key="<%= issue.key -%>" data-issue-component="<%= issue.componentKey() -%>">
+  <div class="code-issue-name">
+    <img src="<%= ApplicationController.root_context -%>/images/priority/<%= issue.severity -%>.png">
+    &nbsp;
+      <span class="rulename">
+        <% rule_name = Internal.rules.ruleL10nName(@issue_results.rule(issue)) %>
+        <a class="open-modal" modal-width="800" href="<%= url_for :controller => 'rules', :action => 'show', :id => issue.rule_key.to_s, :modal => 'true', :layout => 'false' -%>"><%= h rule_name -%></a>
+      </span>
+    &nbsp;
+    <%= image_tag 'sep12.png' -%>
+    &nbsp;
+
+    <%
+       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}"
+    %>
+    <span title="<%= h dates_title -%>"><%= distance_of_time_in_words_to_now(created_at) -%></span>
+    &nbsp;
+    <%
+       if issue.resolution
+    %>
+      <%= image_tag 'sep12.png' -%>
+      &nbsp;
+      <span><%= message("issue.resolution.#{issue.resolution}") -%></span>
+      &nbsp;
+    <% end %>
+    <%
+       if issue.assignee
+    %>
+      <%= image_tag 'sep12.png' -%>
+      &nbsp;
+      <%= message('assigned_to') -%> <%= h(@issue_results.user(issue.assignee).name) -%>
+      &nbsp;
+    <% end %>
+    <%
+       if issue.actionPlanKey()
+    %>
+      <%= image_tag 'sep12.png' -%>
+      &nbsp;
+      <%= message('issue.planned_for_x', :params => h(@issue_results.actionPlan(issue).name())) if @issue_results.actionPlan(issue) -%>
+      &nbsp;
+    <% end %>
+
+  </div>
+
+  <% unless issue.message.blank? %>
+    <div class="code-issue-msg">
+      <%= Api::Utils.split_newlines(h(issue.message)).join('<br/>') -%>
+    </div>
+  <% end %>
+
+  <%
+     issue.comments.each do |comment|
+       comment_html_id = "comment-#{comment.key}-#{rand(100)}"
+  %>
+    <div class="code-issue-comment" id="<%= comment_html_id -%>" data-comment-key="<%= comment.key -%>">
+      <h4>
+        <%= image_tag('reviews/comment.png') -%> &nbsp;<b><%= @issue_results.user(comment.userLogin()).name() -%></b>
+        (<%= distance_of_time_in_words_to_now(Api::Utils.java_to_ruby_datetime(comment.createdAt)) -%>)
+        <% if current_user && current_user.login==comment.userLogin %>
+            &nbsp;
+            <%= image_tag 'sep12.png' -%>
+            &nbsp;
+            <a class="link-action" href="#" onclick="return formEditIssueComment(this)"><%= message('edit') -%></a>
+            <a class="link-action spacer-right" href="#" onclick="return formDeleteIssueComment(this)"><%= message('delete') -%></a>
+        <% end %>
+      </h4>
+      <%= Internal.text.markdownToHtml(comment.markdownText) -%>
+    </div>
+  <% end %>
+
+  <% if current_user %>
+    <div class="code-issue-actions">
+      <a href='#' onclick="return issueForm('comment', this)" class="link-action spacer-right"><%= message('issue.comment.formlink') -%></a>
+      <% unless issue.resolution %>
+        <span class="spacer-right">
+        <a href='#' onclick="return issueForm('assign', this)" class="link-action"><%= message('issue.assign.formlink') -%></a>
+          <% if issue.assignee!=current_user.login %>
+          [<a href="#" onclick="return assignIssueToMe(this)" class="link-action"><%= message('issue.assign.to_me') -%></a>]
+        <% end %>
+        </span>
+      <% end %>
+
+      <% Internal.issues.listTransitions(issue).each do |transition| %>
+        <a href="#" onclick="return doIssueTransition(this, '<%= transition.key -%>')" class="link-action spacer-right"><%= message("issue.transition.#{transition.key}") -%></a>
+      <% end %>
+
+      <% unless issue.resolution %>
+        <a href="#" onclick="return issueForm('severity', this)" class="link-action spacer-right"><%= message("issue.set_severity") -%></a>
+        <a href="#" onclick="return issueForm('plan', this)" class="link-action spacer-right"><%= message("issue.do_plan") -%></a>
+      <% end %>
+    </div>
+    <div class="code-issue-form hidden"></div>
+  <% end %>
+</div>
\ No newline at end of file
index 4d3bec0e7a660a3f033102fbed7fa4234dc8b7d1..244f36b4b29bedddf8d9b9a221bb0bddfa8db946 100644 (file)
@@ -12,6 +12,7 @@
   <input type="hidden" name="id" value="plan"/>
 
   <select name="plan">
+    <option value=""></option>
     <% plans.each do |plan| %>
       <option value="<%= plan.key() -%>"><%= h(plan.name()) -%></option>
     <% end %>
index f8fcee5dfe9278f6566506aa9b556aa83decbc0f..1c671f444b2e03271e62edbe8ceea5a20a5145eb 100644 (file)
@@ -1,3 +1,3 @@
 <div>
-  <%= render :partial => 'resource/issue', :locals => {:issue => @issue_results.issues.get(0)} -%>
+  <%= render :partial => 'issue/issue', :locals => {:issue => @issue_results.issues.get(0)} -%>
 </div>
\ No newline at end of file
index 8d20132bf95e380d77c3b24ffb9fc5279c1fb629..2b5028c551afa9f3af82cf0209cb6cfba44100e4 100644 (file)
@@ -9,7 +9,7 @@
     <% if @display_issues && @global_issues && @global_issues.size>0 -%>
       <div class="code-global-issues">
         <% @global_issues.each do |issue| %>
-          <%= render :partial => 'issue', :locals => {:issue => issue} -%></td>
+          <%= render :partial => 'issue/issue', :locals => {:issue => issue} -%></td>
         <% end %>
       </div>
     <% 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/resource/_issue.html.erb
deleted file mode 100644 (file)
index 4167986..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-<div class="code-issue" data-issue-key="<%= issue.key -%>" data-issue-component="<%= issue.componentKey() -%>">
-  <div class="code-issue-name">
-    <img src="<%= ApplicationController.root_context -%>/images/priority/<%= issue.severity -%>.png">
-    &nbsp;
-      <span class="rulename">
-        <% rule_name = Internal.rules.ruleL10nName(@issue_results.rule(issue)) %>
-        <a class="open-modal" modal-width="800" href="<%= url_for :controller => 'rules', :action => 'show', :id => issue.rule_key.to_s, :modal => 'true', :layout => 'false' -%>"><%= h rule_name -%></a>
-      </span>
-    &nbsp;
-    <%= image_tag 'sep12.png' -%>
-    &nbsp;
-
-    <%
-       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}"
-    %>
-    <span title="<%= h dates_title -%>"><%= distance_of_time_in_words_to_now(created_at) -%></span>
-    &nbsp;
-    <%
-       if issue.resolution
-    %>
-      <%= image_tag 'sep12.png' -%>
-      &nbsp;
-      <span><%= message("issue.resolution.#{issue.resolution}") -%></span>
-      &nbsp;
-    <% end %>
-    <%
-       if issue.assignee
-    %>
-      <%= image_tag 'sep12.png' -%>
-      &nbsp;
-      <%= message('assigned_to') -%> <%= h(@issue_results.user(issue.assignee).name) -%>
-      &nbsp;
-    <% end %>
-    <%
-       if issue.actionPlanKey()
-    %>
-      <%= image_tag 'sep12.png' -%>
-      &nbsp;
-      <%= message('issue.planned_for_x', :params => h(@issue_results.actionPlan(issue).name())) if @issue_results.actionPlan(issue) -%>
-      &nbsp;
-    <% end %>
-
-  </div>
-
-  <% unless issue.message.blank? %>
-    <div class="code-issue-msg">
-      <%= Api::Utils.split_newlines(h(issue.message)).join('<br/>') -%>
-    </div>
-  <% end %>
-
-  <%
-     issue.comments.each do |comment|
-       comment_html_id = "comment-#{comment.key}-#{rand(100)}"
-  %>
-    <div class="code-issue-comment" id="<%= comment_html_id -%>" data-comment-key="<%= comment.key -%>">
-      <h4>
-        <%= image_tag('reviews/comment.png') -%> &nbsp;<b><%= @issue_results.user(comment.userLogin()).name() -%></b>
-        (<%= distance_of_time_in_words_to_now(Api::Utils.java_to_ruby_datetime(comment.createdAt)) -%>)
-        <% if current_user && current_user.login==comment.userLogin %>
-            &nbsp;
-            <%= image_tag 'sep12.png' -%>
-            &nbsp;
-            <a class="link-action" href="#" onclick="return formEditIssueComment(this)"><%= message('edit') -%></a>
-            <a class="link-action spacer-right" href="#" onclick="return formDeleteIssueComment(this)"><%= message('delete') -%></a>
-        <% end %>
-      </h4>
-      <%= Internal.text.markdownToHtml(comment.markdownText) -%>
-    </div>
-  <% end %>
-
-  <% if current_user %>
-    <div class="code-issue-actions">
-      <a href='#' onclick="return issueForm('comment', this)" class="link-action spacer-right"><%= message('issue.comment.formlink') -%></a>
-      <% unless issue.resolution %>
-        <span class="spacer-right">
-        <a href='#' onclick="return issueForm('assign', this)" class="link-action"><%= message('issue.assign.formlink') -%></a>
-          <% if issue.assignee!=current_user.login %>
-          [<a href="#" onclick="return assignIssueToMe(this)" class="link-action"><%= message('issue.assign.to_me') -%></a>]
-        <% end %>
-        </span>
-      <% end %>
-
-      <% Internal.issues.listTransitions(issue.key).each do |transition| %>
-        <a href="#" onclick="return doIssueTransition(this, '<%= transition.key -%>')" class="link-action spacer-right"><%= message("issue.transition.#{transition.key}") -%></a>
-      <% end %>
-
-      <% unless issue.resolution %>
-        <a href="#" onclick="return issueForm('severity', this)" class="link-action spacer-right"><%= message("issue.set_severity") -%></a>
-        <a href="#" onclick="return issueForm('plan', this)" class="link-action spacer-right"><%= message("issue.do_plan") -%></a>
-      <% end %>
-    </div>
-    <div class="code-issue-form hidden"></div>
-  <% end %>
-</div>
\ No newline at end of file
index c0a0f827a4f95a55c11f2f5eb1a49e2e4ab0a97a..882487ff5abb6ae8a430557dfe31d269cdd3b0c1 100644 (file)
@@ -8,7 +8,7 @@
   <td class="lid"></td>
   <td class="code-issues">
     <% line.issues.each_with_index do |issue, index| %>
-      <%= render :partial => 'issue', :locals => {:issue => issue} -%>
+      <%= render :partial => 'issue/issue', :locals => {:issue => issue} -%>
       <% if index < line.issues.size-1 %>
         &nbsp;
       <% end %>