]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3755 Fix performance issue in selectNonClosedIssuesByModule query
authorJulien Lancelot <julien.lancelot@gmail.com>
Fri, 7 Jun 2013 11:50:43 +0000 (13:50 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Fri, 7 Jun 2013 11:50:43 +0000 (13:50 +0200)
plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/issue/IssueTrackingTest.java
sonar-core/src/main/resources/org/sonar/core/issue/db/IssueMapper.xml
sonar-core/src/test/java/org/sonar/core/issue/db/IssueDaoTest.java
sonar-core/src/test/resources/org/sonar/core/issue/db/IssueDaoTest/should_select_non_closed_issues_by_module.xml

index 7611d0ea1deef81d56061106b57c77ddb95c704f..cd2867c0d2f62a0580353190ef15edebf5ea2db3 100644 (file)
@@ -29,13 +29,11 @@ import org.sonar.api.issue.internal.DefaultIssue;
 import org.sonar.api.resources.Project;
 import org.sonar.api.resources.Resource;
 import org.sonar.api.rule.RuleKey;
-import org.sonar.api.utils.DateUtils;
 import org.sonar.batch.scan.LastSnapshots;
 import org.sonar.core.issue.db.IssueDto;
 
 import java.io.IOException;
 import java.util.Arrays;
-import java.util.Date;
 
 import static com.google.common.collect.Lists.newArrayList;
 import static org.fest.assertions.Assertions.assertThat;
@@ -44,8 +42,6 @@ import static org.mockito.Mockito.when;
 
 public class IssueTrackingTest {
 
-  private final Date analysisDate = DateUtils.parseDate("2013-04-11");
-
   IssueTracking tracking;
   Resource project;
   LastSnapshots lastSnapshots;
index e52ab7b86481cc71b95aa74ea46d61d5565aed61..61246d6c239cdda5ca0cf12013a3d053cf88ebc4 100644 (file)
   <select id="selectByKey" parameterType="String" resultType="Issue">
     select
     <include refid="issueColumns"/>
-    from issues i, rules r, projects p, projects root
-    where i.kee=#{kee} and i.rule_id=r.id and p.id=i.component_id and i.root_component_id=root.id
+    from issues i
+    inner join rules r on r.id=i.rule_id
+    inner join projects p on p.id=i.component_id
+    inner join projects root on root.id=i.root_component_id
+    <where>
+      and i.kee=#{kee}
+    </where>
   </select>
 
   <select id="selectNonClosedIssuesByModule" parameterType="int" resultType="Issue">
       r.plugin_rule_key as ruleKey,
       r.plugin_name as ruleRepo,
       p.kee as componentKey
-    from issues i, rules r, projects p
-    where i.status &lt;&gt; 'CLOSED'
-    and (p.root_id=#{id} or (p.root_id is null and p.id=#{id}))
-    and i.component_id=p.id
-    and r.id=i.rule_id
+    from issues i
+    inner join rules r on r.id=i.rule_id
+    inner join (select p.id,p.kee from projects p where (p.root_id=#{id} and p.qualifier &lt;&gt; 'BRC') or (p.id=#{id})) p on p.id=i.component_id
+    <where>
+      and i.status &lt;&gt; 'CLOSED'
+    </where>
   </select>
 
   <select id="selectByIds" parameterType="map" resultType="Issue">
     select
     <include refid="issueColumns"/>
-    from issues i, rules r, projects p, projects root
+    from issues i
+    inner join rules r on r.id=i.rule_id
+    inner join projects p on p.id=i.component_id
+    inner join projects root on root.id=i.root_component_id
     <where>
       and
       <foreach collection="ids" open="i.id in (" close=")" item="list" separator=") or i.id in (">
           #{element}
         </foreach>
       </foreach>
-      and i.rule_id=r.id
-      and p.id=i.component_id
-      and i.root_component_id=root.id
     </where>
     order by i.id desc
   </select>
index b5cbc0a65a70ea889265f9a0ae62783dbe18f20f..504e475cdc32f0a58520447866674c7387759129 100644 (file)
@@ -293,21 +293,20 @@ public class IssueDaoTest extends AbstractDaoTestCase {
   public void should_select_non_closed_issues_by_module() {
     setupData("shared", "should_select_non_closed_issues_by_module");
 
-    // 400 is a non-root module
+    // 400 is a non-root module, we should find 2 issues from classes and one on itself
     DefaultResultHandler handler = new DefaultResultHandler();
     dao.selectNonClosedIssuesByModule(400, handler);
-    assertThat(handler.getResultList()).hasSize(2);
+    assertThat(handler.getResultList()).hasSize(3);
 
     IssueDto issue = (IssueDto) handler.getResultList().get(0);
     assertThat(issue.getRuleRepo()).isNotNull();
     assertThat(issue.getRule()).isNotNull();
     assertThat(issue.getComponentKey()).isNotNull();
 
-    // 399 is the root module. It does not have issues.
+    // 399 is the root module, we should only find 1 issue on itself
     handler = new DefaultResultHandler();
     dao.selectNonClosedIssuesByModule(399, handler);
-    assertThat(handler.getResultList()).isEmpty();
-
+    assertThat(handler.getResultList()).hasSize(1);
   }
 
   @Test
index e276f59a2b19765694f63ec32f35d878dce83aa8..c036dc7c7808c476c52d6bf732d9db742ce2c8e7 100644 (file)
@@ -1,5 +1,6 @@
 <dataset>
 
+  <!-- Open Issue on a file -->
   <issues
       id="100"
       kee="100"
@@ -25,6 +26,7 @@
       updated_at="[null]"
       />
 
+  <!-- Open Issue on a file -->
   <issues
       id="101"
       kee="101"
@@ -37,7 +39,7 @@
       line="120"
       effort_to_fix="[null]"
       status="OPEN"
-      resolution="FIXED"
+      resolution="[null]"
       checksum="[null]"
       reporter="[null]"
       assignee="user"
@@ -50,6 +52,7 @@
       updated_at="[null]"
       />
 
+  <!-- Closed Issue on a file -->
   <issues
       id="102"
       kee="102"
       updated_at="[null]"
       />
 
+  <!-- Open Issue on a sub module -->
+  <issues
+      id="103"
+      kee="103"
+      component_id="400"
+      root_component_id="399"
+      rule_id="501"
+      severity="MAJOR"
+      manual_severity="[false]"
+      message="[null]"
+      line="[null]"
+      effort_to_fix="[null]"
+      status="OPEN"
+      resolution="[null]"
+      checksum="[null]"
+      reporter="[null]"
+      assignee="user"
+      author_login="[null]"
+      issue_attributes="[null]"
+      issue_creation_date="2013-04-16"
+      issue_update_date="2013-04-16"
+      issue_close_date="2013-04-16"
+      created_at="2013-04-10"
+      updated_at="[null]"
+      />
+
+  <!-- Open Issue on a root module -->
+  <issues
+      id="104"
+      kee="104"
+      component_id="399"
+      root_component_id="399"
+      rule_id="501"
+      severity="MAJOR"
+      manual_severity="[false]"
+      message="[null]"
+      line="[null]"
+      effort_to_fix="[null]"
+      status="OPEN"
+      resolution="[null]"
+      checksum="[null]"
+      reporter="[null]"
+      assignee="user"
+      author_login="[null]"
+      issue_attributes="[null]"
+      issue_creation_date="2013-04-16"
+      issue_update_date="2013-04-16"
+      issue_close_date="2013-04-16"
+      created_at="2013-04-10"
+      updated_at="[null]"
+      />
+
 </dataset>