diff options
author | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2016-06-28 17:59:16 +0200 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2016-07-04 15:20:30 +0200 |
commit | ec7f7285d2f8131e52b3f54494c1e7deb1ff450a (patch) | |
tree | b27dc712610efc45f6ceaa4cc9841517a8305797 /sonar-db/src | |
parent | acb655ff30cad999efcd21dafe556429bbb54d11 (diff) | |
download | sonarqube-ec7f7285d2f8131e52b3f54494c1e7deb1ff450a.tar.gz sonarqube-ec7f7285d2f8131e52b3f54494c1e7deb1ff450a.zip |
SONAR-7705 use uuid in PurgeMapper.deleteSnapshots
Diffstat (limited to 'sonar-db/src')
3 files changed, 35 insertions, 24 deletions
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<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(); 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> <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"> 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 @@ -58,6 +58,15 @@ public class PurgeCommandsTest { } /** + * 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. */ @Test |