aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao/src
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-05-26 11:01:42 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-06-01 15:18:14 +0200
commit11073a1928aef0a3a0e8d8bd7fe78fafddff7f25 (patch)
tree4e5c81084688b4fc71cfcdbd52246356e7c62076 /server/sonar-db-dao/src
parentfbb0ea8cc6de8057b82ac842e1eadeaa13624ad3 (diff)
downloadsonarqube-11073a1928aef0a3a0e8d8bd7fe78fafddff7f25.tar.gz
sonarqube-11073a1928aef0a3a0e8d8bd7fe78fafddff7f25.zip
SONAR-9326 drop issues by project_uuid when deleting a project
Diffstat (limited to 'server/sonar-db-dao/src')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java30
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java1
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java4
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml30
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java21
-rw-r--r--server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteResource.xml2
6 files changed, 50 insertions, 38 deletions
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java
index e09b7e7dd11..d57990db4bf 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java
@@ -63,7 +63,7 @@ class PurgeCommands {
profiler.stop();
List<List<String>> analysisUuidsPartitions = Lists.partition(IdUuidPairs.uuids(purgeMapper.selectAnalysisIdsAndUuids(new PurgeSnapshotQuery().setComponentUuid(rootUuid))),
- MAX_SNAPSHOTS_PER_QUERY);
+ MAX_SNAPSHOTS_PER_QUERY);
deleteAnalysisDuplications(analysisUuidsPartitions);
@@ -80,8 +80,8 @@ class PurgeCommands {
void deleteAnalyses(PurgeSnapshotQuery... queries) {
List<IdUuidPair> snapshotIds = from(asList(queries))
- .transformAndConcat(purgeMapper::selectAnalysisIdsAndUuids)
- .toList();
+ .transformAndConcat(purgeMapper::selectAnalysisIdsAndUuids)
+ .toList();
deleteAnalyses(snapshotIds);
}
@@ -115,7 +115,7 @@ class PurgeCommands {
profiler.start("deleteSnapshotWastedMeasures (project_measures)");
List<Long> metricIdsWithoutHistoricalData = purgeMapper.selectMetricIdsWithoutHistoricalData();
analysisUuidsPartitions
- .forEach(analysisUuidsPartition -> purgeMapper.deleteAnalysisWastedMeasures(analysisUuidsPartition, metricIdsWithoutHistoricalData));
+ .forEach(analysisUuidsPartition -> purgeMapper.deleteAnalysisWastedMeasures(analysisUuidsPartition, metricIdsWithoutHistoricalData));
session.commit();
profiler.stop();
@@ -144,6 +144,18 @@ class PurgeCommands {
profiler.stop();
}
+ void deleteIssues(String rootUuid) {
+ profiler.start("deleteIssues (issue_changes)");
+ purgeMapper.deleteComponentIssueChanges(rootUuid);
+ session.commit();
+ profiler.stop();
+
+ profiler.start("deleteIssues (issues)");
+ purgeMapper.deleteComponentIssues(rootUuid);
+ session.commit();
+ profiler.stop();
+ }
+
void deleteComponents(List<IdUuidPair> componentIdUuids) {
List<List<Long>> componentIdPartitions = Lists.partition(IdUuidPairs.ids(componentIdUuids), MAX_RESOURCES_PER_QUERY);
List<List<String>> componentUuidsPartitions = Lists.partition(IdUuidPairs.uuids(componentIdUuids), MAX_RESOURCES_PER_QUERY);
@@ -168,16 +180,6 @@ class PurgeCommands {
session.commit();
profiler.stop();
- profiler.start("deleteComponentIssueChanges (issue_changes)");
- componentUuidsPartitions.forEach(purgeMapper::deleteComponentIssueChanges);
- session.commit();
- profiler.stop();
-
- profiler.start("deleteComponentIssues (issues)");
- componentUuidsPartitions.forEach(purgeMapper::deleteComponentIssues);
- session.commit();
- profiler.stop();
-
profiler.start("deleteResource (projects)");
componentUuidsPartitions.forEach(purgeMapper::deleteComponents);
session.commit();
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java
index 8c411368257..1e804170efd 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java
@@ -162,6 +162,7 @@ public class PurgeDao implements Dao {
commands.deletePermissions(rootId);
commands.deleteAnalyses(rootUuid);
commands.deleteComponents(childrenIds);
+ commands.deleteIssues(rootUuid);
commands.deleteFileSources(rootUuid);
commands.deleteCeActivity(rootUuid);
commands.deleteCeQueue(rootUuid);
diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java
index 3d99f8063be..f860348e6e8 100644
--- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java
+++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java
@@ -68,9 +68,9 @@ public interface PurgeMapper {
List<PurgeableAnalysisDto> selectPurgeableAnalysesWithoutEvents(@Param("componentUuid") String componentUuid);
- void deleteComponentIssueChanges(@Param("componentUuids") List<String> componentUuids);
+ void deleteComponentIssueChanges(@Param("rootUuid") String rootUuid);
- void deleteComponentIssues(@Param("componentUuids") List<String> componentUuids);
+ void deleteComponentIssues(@Param("rootUuid") String rootUuid);
List<String> selectOldClosedIssueKeys(@Param("projectUuid") String projectUuid, @Nullable @Param("toDate") Long toDate);
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
index 6b668699bd9..7a93f7136be 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
@@ -205,36 +205,30 @@
<delete id="deleteComponentIssueChanges" parameterType="map">
delete from issue_changes ic
- where exists (select * from issues i where i.kee=ic.issue_key and i.component_uuid in
- <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
- #{componentUuid,jdbcType=VARCHAR}
- </foreach>
- )
+ where
+ exists (select 1 from issues i where i.kee=ic.issue_key and i.project_uuid = #{rootUuid,jdbcType=VARCHAR})
</delete>
<!-- Mssql -->
<delete id="deleteComponentIssueChanges" databaseId="mssql" parameterType="map">
delete issue_changes from issue_changes
- inner join issues on issue_changes.issue_key=issues.kee
- where issues.component_uuid in
- <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
- #{componentUuid,jdbcType=VARCHAR}
- </foreach>
+ inner join issues on
+ issue_changes.issue_key=issues.kee
+ where
+ issues.project_uuid = #{rootUuid,jdbcType=VARCHAR}
</delete>
<!-- Mysql -->
<delete id="deleteComponentIssueChanges" databaseId="mysql" parameterType="map">
- delete ic from issue_changes as ic, issues as i where ic.issue_key=i.kee and i.component_uuid in
- <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
- #{componentUuid,jdbcType=VARCHAR}
- </foreach>
+ delete ic from issue_changes as ic, issues as i
+ where
+ ic.issue_key=i.kee
+ and i.component_uuid = #{rootUuid,jdbcType=VARCHAR}
</delete>
<delete id="deleteComponentIssues" parameterType="map">
- delete from issues where component_uuid in
- <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
- #{componentUuid,jdbcType=VARCHAR}
- </foreach>
+ delete from issues
+ where project_uuid = #{rootUuid,jdbcType=VARCHAR}
</delete>
<delete id="deleteFileSourcesByProjectUuid">
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java
index 688413d0d14..25c7ee39c21 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java
@@ -91,8 +91,8 @@ public class PurgeCommandsTest {
assertThat(dbTester.countRowsOfTable("projects")).isZero();
assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(1);
assertThat(dbTester.countRowsOfTable("events")).isEqualTo(3);
- assertThat(dbTester.countRowsOfTable("issues")).isZero();
- assertThat(dbTester.countRowsOfTable("issue_changes")).isZero();
+ assertThat(dbTester.countRowsOfTable("issues")).isEqualTo(1);
+ assertThat(dbTester.countRowsOfTable("issue_changes")).isEqualTo(1);
}
@@ -105,11 +105,26 @@ public class PurgeCommandsTest {
assertThat(dbTester.countRowsOfTable("projects")).isEqualTo(1);
assertThat(dbTester.countRowsOfTable("snapshots")).isZero();
- assertThat(dbTester.countRowsOfTable("events")).isEqualTo(0);
+ assertThat(dbTester.countRowsOfTable("events")).isZero();
assertThat(dbTester.countRowsOfTable("issues")).isEqualTo(1);
assertThat(dbTester.countRowsOfTable("issue_changes")).isEqualTo(1);
}
+
+ @Test
+ public void shouldDeleteIssuesAndIssueChanges() {
+ dbTester.prepareDbUnit(getClass(), "shouldDeleteResource.xml");
+
+ PurgeCommands purgeCommands = new PurgeCommands(dbTester.getSession(), profiler);
+ purgeCommands.deleteIssues("uuid_1");
+
+ assertThat(dbTester.countRowsOfTable("projects")).isEqualTo(1);
+ assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(1);
+ assertThat(dbTester.countRowsOfTable("events")).isEqualTo(3);
+ assertThat(dbTester.countRowsOfTable("issues")).isZero();
+ assertThat(dbTester.countRowsOfTable("issue_changes")).isZero();
+ }
+
@Test
public void deletePermissions_deletes_permissions_of_public_project() {
OrganizationDto organization = dbTester.organizations().insert();
diff --git a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteResource.xml b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteResource.xml
index 2d521a1fded..330057a1b73 100644
--- a/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteResource.xml
+++ b/server/sonar-db-dao/src/test/resources/org/sonar/db/purge/PurgeCommandsTest/shouldDeleteResource.xml
@@ -80,7 +80,7 @@
<issues id="1"
kee="ABCDE"
component_uuid="uuid_1"
- project_uuid="1"
+ project_uuid="uuid_1"
status="CLOSED"
resolution="[null]"
line="200"