aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-db-dao
diff options
context:
space:
mode:
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-05-29 11:55:30 +0200
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>2017-05-31 14:55:42 +0200
commit680b2cc53f291a91ef00e54772d82b06baf28a74 (patch)
treedcf6e1f9b42ee5bc4591aee55fca893d9ff97f3e /server/sonar-db-dao
parent16c0c807710622e39deae10cb0a4b880af8e9ef3 (diff)
downloadsonarqube-680b2cc53f291a91ef00e54772d82b06baf28a74.tar.gz
sonarqube-680b2cc53f291a91ef00e54772d82b06baf28a74.zip
SONAR-9334 delete events by project uuid when deleting a project
Diffstat (limited to 'server/sonar-db-dao')
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java133
-rw-r--r--server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java2
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml5
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java2
4 files changed, 76 insertions, 66 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 38e9e8e6140..e09b7e7dd11 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
@@ -57,7 +57,79 @@ class PurgeCommands {
}
void deleteAnalyses(String rootUuid) {
- deleteAnalyses(purgeMapper.selectAnalysisIdsAndUuids(new PurgeSnapshotQuery().setComponentUuid(rootUuid)));
+ profiler.start("deleteAnalyses (events)");
+ purgeMapper.deleteComponentEvents(rootUuid);
+ session.commit();
+ profiler.stop();
+
+ List<List<String>> analysisUuidsPartitions = Lists.partition(IdUuidPairs.uuids(purgeMapper.selectAnalysisIdsAndUuids(new PurgeSnapshotQuery().setComponentUuid(rootUuid))),
+ MAX_SNAPSHOTS_PER_QUERY);
+
+ deleteAnalysisDuplications(analysisUuidsPartitions);
+
+ profiler.start("deleteAnalyses (project_measures)");
+ analysisUuidsPartitions.forEach(purgeMapper::deleteAnalysisMeasures);
+ session.commit();
+ profiler.stop();
+
+ profiler.start("deleteAnalyses (snapshots)");
+ analysisUuidsPartitions.forEach(purgeMapper::deleteAnalyses);
+ session.commit();
+ profiler.stop();
+ }
+
+ void deleteAnalyses(PurgeSnapshotQuery... queries) {
+ List<IdUuidPair> snapshotIds = from(asList(queries))
+ .transformAndConcat(purgeMapper::selectAnalysisIdsAndUuids)
+ .toList();
+ deleteAnalyses(snapshotIds);
+ }
+
+ @VisibleForTesting
+ protected void deleteAnalyses(List<IdUuidPair> analysisIdUuids) {
+ List<List<String>> analysisUuidsPartitions = Lists.partition(IdUuidPairs.uuids(analysisIdUuids), MAX_SNAPSHOTS_PER_QUERY);
+
+ deleteAnalysisDuplications(analysisUuidsPartitions);
+
+ profiler.start("deleteAnalyses (events)");
+ analysisUuidsPartitions.forEach(purgeMapper::deleteAnalysisEvents);
+ session.commit();
+ profiler.stop();
+
+ profiler.start("deleteAnalyses (project_measures)");
+ analysisUuidsPartitions.forEach(purgeMapper::deleteAnalysisMeasures);
+ session.commit();
+ profiler.stop();
+
+ profiler.start("deleteAnalyses (snapshots)");
+ analysisUuidsPartitions.forEach(purgeMapper::deleteAnalyses);
+ session.commit();
+ profiler.stop();
+ }
+
+ public void purgeAnalyses(List<IdUuidPair> analysisUuids) {
+ List<List<String>> analysisUuidsPartitions = Lists.partition(IdUuidPairs.uuids(analysisUuids), MAX_SNAPSHOTS_PER_QUERY);
+
+ deleteAnalysisDuplications(analysisUuidsPartitions);
+
+ profiler.start("deleteSnapshotWastedMeasures (project_measures)");
+ List<Long> metricIdsWithoutHistoricalData = purgeMapper.selectMetricIdsWithoutHistoricalData();
+ analysisUuidsPartitions
+ .forEach(analysisUuidsPartition -> purgeMapper.deleteAnalysisWastedMeasures(analysisUuidsPartition, metricIdsWithoutHistoricalData));
+ session.commit();
+ profiler.stop();
+
+ profiler.start("updatePurgeStatusToOne (snapshots)");
+ analysisUuidsPartitions.forEach(purgeMapper::updatePurgeStatusToOne);
+ session.commit();
+ profiler.stop();
+ }
+
+ private void deleteAnalysisDuplications(List<List<String>> snapshotUuidsPartitions) {
+ profiler.start("deleteAnalysisDuplications (duplications_index)");
+ snapshotUuidsPartitions.forEach(purgeMapper::deleteAnalysisDuplications);
+ session.commit();
+ profiler.stop();
}
void deletePermissions(long rootId) {
@@ -106,11 +178,6 @@ class PurgeCommands {
session.commit();
profiler.stop();
- profiler.start("deleteComponentEvents (events)");
- componentUuidsPartitions.forEach(purgeMapper::deleteComponentEvents);
- session.commit();
- profiler.stop();
-
profiler.start("deleteResource (projects)");
componentUuidsPartitions.forEach(purgeMapper::deleteComponents);
session.commit();
@@ -135,60 +202,6 @@ class PurgeCommands {
profiler.stop();
}
- void deleteAnalyses(PurgeSnapshotQuery... queries) {
- List<IdUuidPair> snapshotIds = from(asList(queries))
- .transformAndConcat(purgeMapper::selectAnalysisIdsAndUuids)
- .toList();
- deleteAnalyses(snapshotIds);
- }
-
- @VisibleForTesting
- protected void deleteAnalyses(List<IdUuidPair> analysisIdUuids) {
- List<List<String>> analysisUuidsPartitions = Lists.partition(IdUuidPairs.uuids(analysisIdUuids), MAX_SNAPSHOTS_PER_QUERY);
-
- deleteAnalysisDuplications(analysisUuidsPartitions);
-
- profiler.start("deleteAnalyses (events)");
- analysisUuidsPartitions.forEach(purgeMapper::deleteAnalysisEvents);
- session.commit();
- profiler.stop();
-
- profiler.start("deleteAnalyses (project_measures)");
- analysisUuidsPartitions.forEach(purgeMapper::deleteAnalysisMeasures);
- session.commit();
- profiler.stop();
-
- profiler.start("deleteAnalyses (snapshots)");
- analysisUuidsPartitions.forEach(purgeMapper::deleteAnalyses);
- session.commit();
- profiler.stop();
- }
-
- public void purgeAnalyses(List<IdUuidPair> analysisUuids) {
- List<List<String>> analysisUuidsPartitions = Lists.partition(IdUuidPairs.uuids(analysisUuids), MAX_SNAPSHOTS_PER_QUERY);
-
- deleteAnalysisDuplications(analysisUuidsPartitions);
-
- profiler.start("deleteSnapshotWastedMeasures (project_measures)");
- List<Long> metricIdsWithoutHistoricalData = purgeMapper.selectMetricIdsWithoutHistoricalData();
- analysisUuidsPartitions.stream()
- .forEach(analysisUuidsPartition -> purgeMapper.deleteAnalysisWastedMeasures(analysisUuidsPartition, metricIdsWithoutHistoricalData));
- session.commit();
- profiler.stop();
-
- profiler.start("updatePurgeStatusToOne (snapshots)");
- analysisUuidsPartitions.forEach(purgeMapper::updatePurgeStatusToOne);
- session.commit();
- profiler.stop();
- }
-
- private void deleteAnalysisDuplications(List<List<String>> snapshotUuidsPartitions) {
- profiler.start("deleteAnalysisDuplications (duplications_index)");
- snapshotUuidsPartitions.forEach(purgeMapper::deleteAnalysisDuplications);
- session.commit();
- profiler.stop();
- }
-
public void deleteFileSources(String rootUuid) {
profiler.start("deleteFileSources (file_sources)");
purgeMapper.deleteFileSourcesByProjectUuid(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 a0e3248320f..3d99f8063be 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
@@ -62,7 +62,7 @@ public interface PurgeMapper {
void deleteComponentManualMeasures(@Param("componentUuids") List<String> componentUuids);
- void deleteComponentEvents(@Param("componentUuids") List<String> componentUuids);
+ void deleteComponentEvents(@Param("componentUuid") String componentUuid);
List<PurgeableAnalysisDto> selectPurgeableAnalysesWithEvents(@Param("componentUuid") String componentUuid);
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 edec6e6e0e5..6b668699bd9 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
@@ -200,10 +200,7 @@
<delete id="deleteComponentEvents" parameterType="map">
delete from events
where
- component_uuid in
- <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
- #{componentUuid,jdbcType=VARCHAR}
- </foreach>
+ component_uuid = #{componentUuid,jdbcType=VARCHAR}
</delete>
<delete id="deleteComponentIssueChanges" parameterType="map">
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 2a33ea8c06d..688413d0d14 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
@@ -90,7 +90,7 @@ public class PurgeCommandsTest {
assertThat(dbTester.countRowsOfTable("projects")).isZero();
assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(1);
- assertThat(dbTester.countRowsOfTable("events")).isZero();
+ assertThat(dbTester.countRowsOfTable("events")).isEqualTo(3);
assertThat(dbTester.countRowsOfTable("issues")).isZero();
assertThat(dbTester.countRowsOfTable("issue_changes")).isZero();
}