]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9334 delete events by project uuid when deleting a project 2117/head
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 29 May 2017 09:55:30 +0000 (11:55 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 31 May 2017 12:55:42 +0000 (14:55 +0200)
server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java
server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java

index 38e9e8e61402a5b7a08bd00f168a47341b7df2e1..e09b7e7dd1155ce25b27638bd0a2ea754dae85b3 100644 (file)
@@ -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);
index a0e3248320f9bcd7772aa86749e282fc5c273f61..3d99f8063be3bfac3bad61af66a9a40e3c9b877f 100644 (file)
@@ -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);
 
index edec6e6e0e5eb3839ce87673aa4c2bb8226b06ee..6b668699bd9549903b1e6262ba33aab6fdad7d57 100644 (file)
   <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">
index 2a33ea8c06d66c8eb0360a1656842b1ab86a77ec..688413d0d14c5ae920d45ecf7b6b19a1a235b7d1 100644 (file)
@@ -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();
   }