]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7705 use uuid in PurgeMapper.deleteSnapshots
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 28 Jun 2016 15:59:16 +0000 (17:59 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Mon, 4 Jul 2016 13:20:30 +0000 (15:20 +0200)
sonar-db/src/main/java/org/sonar/db/purge/PurgeCommands.java
sonar-db/src/main/resources/org/sonar/db/purge/PurgeMapper.xml
sonar-db/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java

index 27248d17ce9f1cf981fdc1ffcbd80d78339bf622..bcfd60c6eb2038945ca0804b4497c8e2f3c05fd4 100644 (file)
@@ -154,28 +154,28 @@ class PurgeCommands {
 
   @VisibleForTesting
   protected void deleteSnapshots(List<IdUuidPair> snapshotIds) {
-    List<List<Long>> snapshotIdsPartition = Lists.partition(IdUuidPairs.ids(snapshotIds), MAX_SNAPSHOTS_PER_QUERY);
-    List<List<String>> snapshotUuidsPartition = Lists.partition(IdUuidPairs.uuids(snapshotIds), MAX_SNAPSHOTS_PER_QUERY);
+    List<List<Long>> snapshotIdsPartitions = Lists.partition(IdUuidPairs.ids(snapshotIds), MAX_SNAPSHOTS_PER_QUERY);
+    List<List<String>> snapshotUuidsPartitions = Lists.partition(IdUuidPairs.uuids(snapshotIds), MAX_SNAPSHOTS_PER_QUERY);
 
-    deleteSnapshotDuplications(snapshotUuidsPartition);
+    deleteSnapshotDuplications(snapshotUuidsPartitions);
 
     profiler.start("deleteSnapshotEvents (events)");
-    for (List<String> partSnapshotUuids : snapshotUuidsPartition) {
-      purgeMapper.deleteSnapshotEvents(partSnapshotUuids);
+    for (List<String> snapshotUuidsPartition : snapshotUuidsPartitions) {
+      purgeMapper.deleteSnapshotEvents(snapshotUuidsPartition);
     }
     session.commit();
     profiler.stop();
 
     profiler.start("deleteSnapshotMeasures (project_measures)");
-    for (List<Long> partSnapshotIds : snapshotIdsPartition) {
-      purgeMapper.deleteSnapshotMeasures(partSnapshotIds);
+    for (List<Long> snapshotIdsPartition : snapshotIdsPartitions) {
+      purgeMapper.deleteSnapshotMeasures(snapshotIdsPartition);
     }
     session.commit();
     profiler.stop();
 
     profiler.start("deleteSnapshot (snapshots)");
-    for (List<Long> partSnapshotIds : snapshotIdsPartition) {
-      purgeMapper.deleteSnapshot(partSnapshotIds);
+    for (List<String> snapshotUuidsPartition : snapshotUuidsPartitions) {
+      purgeMapper.deleteSnapshot(snapshotUuidsPartition);
     }
     session.commit();
     profiler.stop();
@@ -183,31 +183,31 @@ class PurgeCommands {
 
   @VisibleForTesting
   protected void deleteAnalyses(List<IdUuidPair> analysisIdUuids) {
-    List<List<Long>> snapshotIdsPartition = Lists.partition(IdUuidPairs.ids(analysisIdUuids), MAX_SNAPSHOTS_PER_QUERY);
-    List<List<String>> snapshotUuidsPartition = Lists.partition(IdUuidPairs.uuids(analysisIdUuids), MAX_SNAPSHOTS_PER_QUERY);
+    List<List<Long>> snapshotIdsPartitions = Lists.partition(IdUuidPairs.ids(analysisIdUuids), MAX_SNAPSHOTS_PER_QUERY);
+    List<List<String>> snapshotUuidsPartitions = Lists.partition(IdUuidPairs.uuids(analysisIdUuids), MAX_SNAPSHOTS_PER_QUERY);
 
-    deleteSnapshotDuplications(snapshotUuidsPartition);
+    deleteSnapshotDuplications(snapshotUuidsPartitions);
 
     profiler.start("deleteAnalyses (events)");
-    for (List<String> partSnapshotUuids : snapshotUuidsPartition) {
-      purgeMapper.deleteSnapshotEvents(partSnapshotUuids);
+    for (List<String> snapshotUuidsPartition : snapshotUuidsPartitions) {
+      purgeMapper.deleteSnapshotEvents(snapshotUuidsPartition);
     }
     session.commit();
     profiler.stop();
 
     profiler.start("deleteAnalyses (project_measures)");
-    for (List<Long> partSnapshotIds : snapshotIdsPartition) {
-      purgeMapper.deleteSnapshotMeasures(partSnapshotIds);
+    for (List<Long> snapshotIdsPartition : snapshotIdsPartitions) {
+      purgeMapper.deleteSnapshotMeasures(snapshotIdsPartition);
     }
     session.commit();
     profiler.stop();
 
     profiler.start("deleteAnalyses (snapshots)");
-    for (List<String> partSnapshotUuids : snapshotUuidsPartition) {
-      purgeMapper.deleteAnalyses(partSnapshotUuids);
+    for (List<String> snapshotUuidsPartition : snapshotUuidsPartitions) {
+      purgeMapper.deleteAnalyses(snapshotUuidsPartition);
     }
-    for (List<Long> snapshotIdPartition : snapshotIdsPartition) {
-      purgeMapper.deleteDescendantSnapshots(snapshotIdPartition);
+    for (List<Long> snapshotIdsPartition : snapshotIdsPartitions) {
+      purgeMapper.deleteDescendantSnapshots(snapshotIdsPartition);
     }
     session.commit();
     profiler.stop();
index 39914441ae8063a23e5c41abd5ee247b2322fb23..45e05bc360749b4d0a8211d2c3cf85f33f8e223e 100644 (file)
   </delete>
 
   <delete id="deleteSnapshot" parameterType="map">
-    delete from snapshots where id in
-    <foreach collection="snapshotIds" open="(" close=")" item="snapshotId" separator=",">
-      #{snapshotId}
-    </foreach>
+    delete from snapshots
+    where
+      uuid in
+      <foreach collection="snapshotUuids" open="(" close=")" item="snapshotUuid" separator=",">
+        #{snapshotUuid}
+      </foreach>
   </delete>
 
   <delete id="deleteAnalyses" parameterType="map">
index 81ffbc99a4b4905b849d7e390833d6573b079ef0..7507d1db6808d51d44f23f1e8ea6427387e5e299 100644 (file)
@@ -57,6 +57,15 @@ public class PurgeCommandsTest {
     // The goal of this test is only to check that the query do no fail, not to check result
   }
 
+  /**
+   * Test that SQL queries execution do not fail with a huge number of parameter
+   */
+  @Test
+  public void should_not_fail_when_deleting_huge_number_of_analyses() {
+    new PurgeCommands(dbTester.getSession(), profiler).deleteAnalyses(getHugeNumberOfIdUuidPairs());
+    // The goal of this test is only to check that the query do no fail, not to check result
+  }
+
   /**
    * Test that all related data is purged.
    */