From: Sébastien Lesaint Date: Tue, 28 Jun 2016 15:59:16 +0000 (+0200) Subject: SONAR-7705 use uuid in PurgeMapper.deleteSnapshots X-Git-Tag: 6.0-RC1~180 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ec7f7285d2f8131e52b3f54494c1e7deb1ff450a;p=sonarqube.git SONAR-7705 use uuid in PurgeMapper.deleteSnapshots --- diff --git a/sonar-db/src/main/java/org/sonar/db/purge/PurgeCommands.java b/sonar-db/src/main/java/org/sonar/db/purge/PurgeCommands.java index 27248d17ce9..bcfd60c6eb2 100644 --- a/sonar-db/src/main/java/org/sonar/db/purge/PurgeCommands.java +++ b/sonar-db/src/main/java/org/sonar/db/purge/PurgeCommands.java @@ -154,28 +154,28 @@ class PurgeCommands { @VisibleForTesting protected void deleteSnapshots(List snapshotIds) { - List> snapshotIdsPartition = Lists.partition(IdUuidPairs.ids(snapshotIds), MAX_SNAPSHOTS_PER_QUERY); - List> snapshotUuidsPartition = Lists.partition(IdUuidPairs.uuids(snapshotIds), MAX_SNAPSHOTS_PER_QUERY); + List> snapshotIdsPartitions = Lists.partition(IdUuidPairs.ids(snapshotIds), MAX_SNAPSHOTS_PER_QUERY); + List> snapshotUuidsPartitions = Lists.partition(IdUuidPairs.uuids(snapshotIds), MAX_SNAPSHOTS_PER_QUERY); - deleteSnapshotDuplications(snapshotUuidsPartition); + deleteSnapshotDuplications(snapshotUuidsPartitions); profiler.start("deleteSnapshotEvents (events)"); - for (List partSnapshotUuids : snapshotUuidsPartition) { - purgeMapper.deleteSnapshotEvents(partSnapshotUuids); + for (List snapshotUuidsPartition : snapshotUuidsPartitions) { + purgeMapper.deleteSnapshotEvents(snapshotUuidsPartition); } session.commit(); profiler.stop(); profiler.start("deleteSnapshotMeasures (project_measures)"); - for (List partSnapshotIds : snapshotIdsPartition) { - purgeMapper.deleteSnapshotMeasures(partSnapshotIds); + for (List snapshotIdsPartition : snapshotIdsPartitions) { + purgeMapper.deleteSnapshotMeasures(snapshotIdsPartition); } session.commit(); profiler.stop(); profiler.start("deleteSnapshot (snapshots)"); - for (List partSnapshotIds : snapshotIdsPartition) { - purgeMapper.deleteSnapshot(partSnapshotIds); + for (List snapshotUuidsPartition : snapshotUuidsPartitions) { + purgeMapper.deleteSnapshot(snapshotUuidsPartition); } session.commit(); profiler.stop(); @@ -183,31 +183,31 @@ class PurgeCommands { @VisibleForTesting protected void deleteAnalyses(List analysisIdUuids) { - List> snapshotIdsPartition = Lists.partition(IdUuidPairs.ids(analysisIdUuids), MAX_SNAPSHOTS_PER_QUERY); - List> snapshotUuidsPartition = Lists.partition(IdUuidPairs.uuids(analysisIdUuids), MAX_SNAPSHOTS_PER_QUERY); + List> snapshotIdsPartitions = Lists.partition(IdUuidPairs.ids(analysisIdUuids), MAX_SNAPSHOTS_PER_QUERY); + List> snapshotUuidsPartitions = Lists.partition(IdUuidPairs.uuids(analysisIdUuids), MAX_SNAPSHOTS_PER_QUERY); - deleteSnapshotDuplications(snapshotUuidsPartition); + deleteSnapshotDuplications(snapshotUuidsPartitions); profiler.start("deleteAnalyses (events)"); - for (List partSnapshotUuids : snapshotUuidsPartition) { - purgeMapper.deleteSnapshotEvents(partSnapshotUuids); + for (List snapshotUuidsPartition : snapshotUuidsPartitions) { + purgeMapper.deleteSnapshotEvents(snapshotUuidsPartition); } session.commit(); profiler.stop(); profiler.start("deleteAnalyses (project_measures)"); - for (List partSnapshotIds : snapshotIdsPartition) { - purgeMapper.deleteSnapshotMeasures(partSnapshotIds); + for (List snapshotIdsPartition : snapshotIdsPartitions) { + purgeMapper.deleteSnapshotMeasures(snapshotIdsPartition); } session.commit(); profiler.stop(); profiler.start("deleteAnalyses (snapshots)"); - for (List partSnapshotUuids : snapshotUuidsPartition) { - purgeMapper.deleteAnalyses(partSnapshotUuids); + for (List snapshotUuidsPartition : snapshotUuidsPartitions) { + purgeMapper.deleteAnalyses(snapshotUuidsPartition); } - for (List snapshotIdPartition : snapshotIdsPartition) { - purgeMapper.deleteDescendantSnapshots(snapshotIdPartition); + for (List snapshotIdsPartition : snapshotIdsPartitions) { + purgeMapper.deleteDescendantSnapshots(snapshotIdsPartition); } session.commit(); profiler.stop(); diff --git a/sonar-db/src/main/resources/org/sonar/db/purge/PurgeMapper.xml b/sonar-db/src/main/resources/org/sonar/db/purge/PurgeMapper.xml index 39914441ae8..45e05bc3607 100644 --- a/sonar-db/src/main/resources/org/sonar/db/purge/PurgeMapper.xml +++ b/sonar-db/src/main/resources/org/sonar/db/purge/PurgeMapper.xml @@ -113,10 +113,12 @@ - delete from snapshots where id in - - #{snapshotId} - + delete from snapshots + where + uuid in + + #{snapshotUuid} + diff --git a/sonar-db/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java b/sonar-db/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java index 81ffbc99a4b..7507d1db680 100644 --- a/sonar-db/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java +++ b/sonar-db/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java @@ -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. */