]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3755 Delete limitation of max number of issues when loading issue changes
authorJulien Lancelot <julien.lancelot@gmail.com>
Wed, 12 Jun 2013 15:25:50 +0000 (17:25 +0200)
committerJulien Lancelot <julien.lancelot@gmail.com>
Wed, 12 Jun 2013 15:25:50 +0000 (17:25 +0200)
sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java
sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeMapper.java
sonar-core/src/main/resources/org/sonar/core/issue/db/IssueChangeMapper.xml
sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java

index 3061586f253a4bd1fd3423f86c2fc7f8938eb253..cf9e5c6a67853f74f97bd1da64bdf3a011a95748 100644 (file)
@@ -20,7 +20,6 @@
 
 package org.sonar.core.issue.db;
 
-import com.google.common.base.Preconditions;
 import com.google.common.collect.Lists;
 import org.apache.ibatis.session.SqlSession;
 import org.sonar.api.BatchComponent;
@@ -30,11 +29,14 @@ import org.sonar.api.issue.internal.FieldDiffs;
 import org.sonar.core.persistence.MyBatis;
 
 import javax.annotation.CheckForNull;
+
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
+import static com.google.common.collect.Lists.newArrayList;
+
 /**
  * @since 3.6
  */
@@ -81,12 +83,13 @@ public class IssueChangeDao implements BatchComponent, ServerComponent {
   }
 
   List<IssueChangeDto> selectByIssuesAndType(SqlSession session, Collection<String> issueKeys, String changeType) {
-    Preconditions.checkArgument(issueKeys.size() < 1000, "Number of issue keys is greater than or equal 1000");
     if (issueKeys.isEmpty()) {
       return Collections.emptyList();
     }
     IssueChangeMapper mapper = session.getMapper(IssueChangeMapper.class);
-    return mapper.selectByIssuesAndType(issueKeys, changeType);
+
+    List<List<String>> keysPartition = Lists.partition(newArrayList(issueKeys), 1000);
+    return mapper.selectByIssuesAndType(keysPartition, changeType);
   }
 
   public boolean delete(String key) {
index b9c85f78fb130fba8a739093fd17b62310c4d205..edb57a03bcd8f803b65cf1c30a5c02c42aaea1e3 100644 (file)
@@ -23,7 +23,7 @@ package org.sonar.core.issue.db;
 import org.apache.ibatis.annotations.Param;
 
 import javax.annotation.CheckForNull;
-import java.util.Collection;
+
 import java.util.List;
 
 /**
@@ -43,7 +43,7 @@ public interface IssueChangeMapper {
   /**
    * Issue changes by chronological date of creation
    */
-  List<IssueChangeDto> selectByIssuesAndType(@Param("issueKeys") Collection<String> issueKeys,
+  List<IssueChangeDto> selectByIssuesAndType(@Param("issueKeys") List<List<String>> issueKeys,
                                              @Param("changeType") String changeType);
 
   List<IssueChangeDto> selectByIssue(String issueKey);
index 83cd957bd93330a64997e546d2e30dd9b53836e7..1620663a1ff8dd224477468ea02828e67db51112 100644 (file)
@@ -1,25 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" ?>
 
-<!--
-  ~ SonarQube, open source software quality management tool.
-  ~ Copyright (C) 2008-2013 SonarSource
-  ~ mailto:contact AT sonarsource DOT com
-  ~
-  ~ SonarQube is free software; you can redistribute it and/or
-  ~ modify it under the terms of the GNU Lesser General Public
-  ~ License as published by the Free Software Foundation; either
-  ~ version 3 of the License, or (at your option) any later version.
-  ~
-  ~ SonarQube is distributed in the hope that it will be useful,
-  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
-  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-  ~ Lesser General Public License for more details.
-  ~
-  ~ You should have received a copy of the GNU Lesser General Public License
-  ~ along with this program; if not, write to the Free Software Foundation,
-  ~ Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-  -->
-
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mappei.dtd">
 
 <mapper namespace="org.sonar.core.issue.db.IssueChangeMapper">
     select
     <include refid="issueChangeColumns"/>
     from issue_changes c
-    where c.change_type=#{changeType} and c.issue_key in (
-    <foreach collection="issueKeys" item="key" separator=",">#{key}</foreach>
-    )
+    where c.change_type=#{changeType} and
+    <foreach collection="issueKeys" open="c.issue_key in (" close=")" item="list" separator=") or c.issue_key in (">
+      <foreach collection="list" item="element" separator=",">
+        #{element}
+      </foreach>
+    </foreach>
     order by c.created_at
   </select>
 
index 239168c3cc1c5381a9598495027e8d0dfbbae631..95e524dfe4008d71d5efd064ba5915cf19480b2b 100644 (file)
@@ -32,6 +32,7 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
+import static com.google.common.collect.Lists.newArrayList;
 import static org.fest.assertions.Assertions.assertThat;
 import static org.mockito.Mockito.mock;
 
@@ -64,6 +65,22 @@ public class IssueChangeDaoTest extends AbstractDaoTestCase {
     assertThat(second.markdownText()).isEqualTo("recent comment");
   }
 
+  @Test
+  public void selectCommentsByIssuesOnHugeNumberOfIssues() {
+    setupData("shared");
+
+    SqlSession session = getMyBatis().openSession();
+    List<String> hugeNbOfIssues = newArrayList();
+    for (int i=0; i<1500; i++) {
+      hugeNbOfIssues.add("ABCD"+i);
+    }
+    List<DefaultIssueComment> comments = dao.selectCommentsByIssues(session, hugeNbOfIssues);
+    MyBatis.closeQuietly(session);
+
+    // The goal of this test is only to check that the query do no fail, not to check the number of results
+    assertThat(comments).isEmpty();
+  }
+
   @Test
   public void selectCommentByKey() {
     setupData("shared");
@@ -77,7 +94,6 @@ public class IssueChangeDaoTest extends AbstractDaoTestCase {
     assertThat(dao.selectCommentByKey("UNKNOWN")).isNull();
   }
 
-
   @Test
   public void selectIssueChangelog() {
     setupData("shared");