From 7f1d0426458733fb7bde55e103a44ace814a5fe0 Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Wed, 12 Jun 2013 17:25:50 +0200 Subject: [PATCH] SONAR-3755 Delete limitation of max number of issues when loading issue changes (cherry picked from commit 9e1f713) --- .../sonar/core/issue/db/IssueChangeDao.java | 9 ++++++--- .../sonar/core/issue/db/IssueChangeMapper.java | 4 ++-- .../sonar/core/issue/db/IssueChangeMapper.xml | 9 ++++++--- .../core/issue/db/IssueChangeDaoTest.java | 18 +++++++++++++++++- 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java index 3061586f253..cf9e5c6a678 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeDao.java @@ -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 selectByIssuesAndType(SqlSession session, Collection 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> keysPartition = Lists.partition(newArrayList(issueKeys), 1000); + return mapper.selectByIssuesAndType(keysPartition, changeType); } public boolean delete(String key) { diff --git a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeMapper.java b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeMapper.java index b9c85f78fb1..edb57a03bcd 100644 --- a/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeMapper.java +++ b/sonar-core/src/main/java/org/sonar/core/issue/db/IssueChangeMapper.java @@ -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 selectByIssuesAndType(@Param("issueKeys") Collection issueKeys, + List selectByIssuesAndType(@Param("issueKeys") List> issueKeys, @Param("changeType") String changeType); List selectByIssue(String issueKey); diff --git a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueChangeMapper.xml b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueChangeMapper.xml index 0d1c57ee136..1620663a1ff 100644 --- a/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueChangeMapper.xml +++ b/sonar-core/src/main/resources/org/sonar/core/issue/db/IssueChangeMapper.xml @@ -42,9 +42,12 @@ select from issue_changes c - where c.change_type=#{changeType} and c.issue_key in ( - #{key} - ) + where c.change_type=#{changeType} and + + + #{element} + + order by c.created_at diff --git a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java index 239168c3cc1..95e524dfe40 100644 --- a/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java +++ b/sonar-core/src/test/java/org/sonar/core/issue/db/IssueChangeDaoTest.java @@ -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 hugeNbOfIssues = newArrayList(); + for (int i=0; i<1500; i++) { + hugeNbOfIssues.add("ABCD"+i); + } + List 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"); -- 2.39.5