aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao/src
diff options
context:
space:
mode:
authorJacek <jacek.poreda@sonarsource.com>2022-05-24 10:08:46 +0200
committersonartech <sonartech@sonarsource.com>2022-05-24 20:10:14 +0000
commitb66ff887e1ad3a81ef438a3832818e61c03eebd7 (patch)
treeb14482e5691081cbeee7d058561d83b0be06552b /server/sonar-db-dao/src
parent914cef832bc5e781c560d6d476ccba93caf7eefc (diff)
downloadsonarqube-b66ff887e1ad3a81ef438a3832818e61c03eebd7.tar.gz
sonarqube-b66ff887e1ad3a81ef438a3832818e61c03eebd7.zip
SONAR-16431 Fix project recomputation failure when project is part of large portfolio
Diffstat (limited to 'server/sonar-db-dao/src')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java2
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java37
2 files changed, 25 insertions, 14 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java
index a9d680ad75d..64dbe688486 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/project/ProjectDao.java
@@ -98,7 +98,7 @@ public class ProjectDao implements Dao {
if (uuids.isEmpty()) {
return Collections.emptyList();
}
- return mapper(session).selectByUuids(uuids);
+ return executeLargeInputs(uuids, partition -> mapper(session).selectByUuids(partition));
}
public void updateVisibility(DbSession session, String uuid, boolean isPrivate) {
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java
index 3aeabbd7546..ea65092c688 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/project/ProjectDaoTest.java
@@ -27,6 +27,7 @@ import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
+import java.util.stream.IntStream;
import javax.annotation.Nullable;
import org.assertj.core.groups.Tuple;
import org.junit.Rule;
@@ -66,7 +67,7 @@ public class ProjectDaoTest {
Optional<ProjectDto> projectByUuid = projectDao.selectByUuid(db.getSession(), "uuid_o1_p1");
assertThat(projectByUuid).isPresent();
- assertProject(projectByUuid.get(), "projectName_p1", "projectKee_o1_p1", "uuid_o1_p1", "desc_p1", "tag1,tag2", false);
+ assertProject(projectByUuid.get(), "projectName_p1", "projectKee_o1_p1", "uuid_o1_p1", "desc_p1", "tag1,tag2", false);
assertThat(projectByUuid.get().isPrivate()).isFalse();
}
@@ -78,7 +79,7 @@ public class ProjectDaoTest {
Optional<ProjectDto> projectByKee = projectDao.selectProjectByKey(db.getSession(), "projectKee_o1_p1");
assertThat(projectByKee).isPresent();
- assertProject(projectByKee.get(), "projectName_p1", "projectKee_o1_p1", "uuid_o1_p1", "desc_p1", "tag1,tag2", false);
+ assertProject(projectByKee.get(), "projectName_p1", "projectKee_o1_p1", "uuid_o1_p1", "desc_p1", "tag1,tag2", false);
}
@Test
@@ -151,8 +152,8 @@ public class ProjectDaoTest {
List<ProjectDto> projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2")));
assertThat(projectsByUuids).hasSize(2);
- assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "uuid_o1_p1", "desc_p1", null, false);
- assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "uuid_o1_p2", "desc_p2", "tag1,tag2", false);
+ assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "uuid_o1_p1", "desc_p1", null, false);
+ assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "uuid_o1_p2", "desc_p2", "tag1,tag2", false);
dto1.setTags(Collections.singletonList("tag3"));
dto2.setTagsString("");
@@ -161,8 +162,8 @@ public class ProjectDaoTest {
projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2")));
assertThat(projectsByUuids).hasSize(2);
- assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "uuid_o1_p1", "desc_p1", "tag3", false);
- assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "uuid_o1_p2", "desc_p2", null, false);
+ assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "uuid_o1_p1", "desc_p1", "tag3", false);
+ assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "uuid_o1_p2", "desc_p2", null, false);
assertThat(projectsByUuids.get(0).getTags()).containsOnly("tag3");
}
@@ -177,16 +178,16 @@ public class ProjectDaoTest {
List<ProjectDto> projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2")));
assertThat(projectsByUuids).hasSize(2);
- assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "uuid_o1_p1", "desc_p1", "tag1,tag2", true);
- assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "uuid_o1_p2", "desc_p2", "tag1,tag2", false);
+ assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "uuid_o1_p1", "desc_p1", "tag1,tag2", true);
+ assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "uuid_o1_p2", "desc_p2", "tag1,tag2", false);
projectDao.updateVisibility(db.getSession(), dto1.getUuid(), false);
projectDao.updateVisibility(db.getSession(), dto2.getUuid(), true);
projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2")));
assertThat(projectsByUuids).hasSize(2);
- assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "uuid_o1_p1", "desc_p1", "tag1,tag2", false);
- assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "uuid_o1_p2", "desc_p2", "tag1,tag2", true);
+ assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "uuid_o1_p1", "desc_p1", "tag1,tag2", false);
+ assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "uuid_o1_p2", "desc_p2", "tag1,tag2", true);
}
@Test
@@ -201,8 +202,18 @@ public class ProjectDaoTest {
List<ProjectDto> projectsByUuids = projectDao.selectByUuids(db.getSession(), new HashSet<>(Arrays.asList("uuid_o1_p1", "uuid_o1_p2")));
assertThat(projectsByUuids).hasSize(2);
- assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "uuid_o1_p1", "desc_p1", "tag1,tag2", false);
- assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "uuid_o1_p2", "desc_p2", "tag1,tag2", false);
+ assertProject(projectsByUuids.get(0), "projectName_p1", "projectKee_o1_p1", "uuid_o1_p1", "desc_p1", "tag1,tag2", false);
+ assertProject(projectsByUuids.get(1), "projectName_p2", "projectKee_o1_p2", "uuid_o1_p2", "desc_p2", "tag1,tag2", false);
+ }
+
+ @Test
+ public void select_by_uuids_over_1000() {
+ IntStream.range(0, 1005).mapToObj(value -> createProject("o1", "p" + value))
+ .forEach(projectDto -> projectDao.insert(db.getSession(), projectDto));
+
+ var projectUuids = projectDao.selectAll(db.getSession()).stream().map(ProjectDto::getUuid).collect(Collectors.toSet());
+ List<ProjectDto> projectsByUuids = projectDao.selectByUuids(db.getSession(), projectUuids);
+ assertThat(projectsByUuids).hasSize(1005);
}
@Test
@@ -247,7 +258,7 @@ public class ProjectDaoTest {
}
private void assertProject(ProjectDto dto, String name, String kee, String uuid, String desc, @Nullable String tags, boolean isPrivate) {
- assertThat(dto).extracting("name", "kee", "key","uuid", "description", "tagsString", "private")
+ assertThat(dto).extracting("name", "kee", "key", "uuid", "description", "tagsString", "private")
.containsExactly(name, kee, kee, uuid, desc, tags, isPrivate);
}