From b14b1487909b9d7fc8980fd90f19224005f7664f Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Thu, 30 Jun 2016 16:03:06 +0200 Subject: [PATCH] SONAR-7705 remove dead code and dead sql in purge --- .../org/sonar/db/purge/PurgeCommands.java | 34 +++++----- .../java/org/sonar/db/purge/PurgeDao.java | 2 +- .../java/org/sonar/db/purge/PurgeMapper.java | 13 ++-- .../sonar/db/purge/PurgeSnapshotQuery.java | 29 --------- .../org/sonar/db/purge/PurgeMapper.xml | 63 +++++-------------- .../org/sonar/db/purge/PurgeCommandsTest.java | 2 +- .../java/org/sonar/db/purge/PurgeDaoTest.java | 24 +++---- ....xml => shouldSelectPurgeableAnalysis.xml} | 0 8 files changed, 50 insertions(+), 117 deletions(-) rename sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/{shouldSelectPurgeableSnapshots.xml => shouldSelectPurgeableAnalysis.xml} (100%) 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 03d53ea9d30..a7b82fcd1f1 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 @@ -49,15 +49,15 @@ class PurgeCommands { } List selectSnapshotUuids(PurgeSnapshotQuery query) { - return purgeMapper.selectSnapshotIdsAndUuids(query).stream().map(IdUuidPair::getUuid).collect(Collectors.toList()); + return purgeMapper.selectAnalysisIdsAndUuids(query).stream().map(IdUuidPair::getUuid).collect(Collectors.toList()); } List selectSnapshotIdUuids(PurgeSnapshotQuery query) { - return purgeMapper.selectSnapshotIdsAndUuids(query); + return purgeMapper.selectAnalysisIdsAndUuids(query); } void deleteAnalyses(String rootUuid) { - deleteAnalyses(purgeMapper.selectSnapshotIdsAndUuids(PurgeSnapshotQuery.create().setComponentUuid(rootUuid))); + deleteAnalyses(purgeMapper.selectAnalysisIdsAndUuids(PurgeSnapshotQuery.create().setComponentUuid(rootUuid))); } void deleteComponents(List componentIdUuids) { @@ -127,7 +127,7 @@ class PurgeCommands { void deleteSnapshots(PurgeSnapshotQuery... queries) { List snapshotIds = from(asList(queries)) - .transformAndConcat(purgeMapper::selectSnapshotIdsAndUuids) + .transformAndConcat(purgeMapper::selectAnalysisIdsAndUuids) .toList(); deleteSnapshots(snapshotIds); } @@ -137,20 +137,20 @@ class PurgeCommands { List> snapshotIdsPartitions = Lists.partition(IdUuidPairs.ids(snapshotIds), MAX_SNAPSHOTS_PER_QUERY); List> snapshotUuidsPartitions = Lists.partition(IdUuidPairs.uuids(snapshotIds), MAX_SNAPSHOTS_PER_QUERY); - deleteSnapshotDuplications(snapshotUuidsPartitions); + deleteAnalysisDuplications(snapshotUuidsPartitions); - profiler.start("deleteSnapshotEvents (events)"); - snapshotUuidsPartitions.forEach(purgeMapper::deleteSnapshotEvents); + profiler.start("deleteSnapshots (events)"); + snapshotUuidsPartitions.forEach(purgeMapper::deleteAnalysisEvents); session.commit(); profiler.stop(); - profiler.start("deleteSnapshotMeasures (project_measures)"); + profiler.start("deleteSnapshots (project_measures)"); snapshotIdsPartitions.forEach(purgeMapper::deleteSnapshotMeasures); session.commit(); profiler.stop(); - profiler.start("deleteSnapshot (snapshots)"); - snapshotUuidsPartitions.forEach(purgeMapper::deleteSnapshot); + profiler.start("deleteSnapshots (snapshots)"); + snapshotUuidsPartitions.forEach(purgeMapper::deleteAnalyses); session.commit(); profiler.stop(); } @@ -175,7 +175,7 @@ class PurgeCommands { void deleteAnalyses(PurgeSnapshotQuery... queries) { List snapshotIds = from(asList(queries)) - .transformAndConcat(purgeMapper::selectSnapshotIdsAndUuids) + .transformAndConcat(purgeMapper::selectAnalysisIdsAndUuids) .toList(); deleteAnalyses(snapshotIds); } @@ -185,10 +185,10 @@ class PurgeCommands { List> analysisIdsPartitions = Lists.partition(IdUuidPairs.ids(analysisIdUuids), MAX_SNAPSHOTS_PER_QUERY); List> analysisUuidsPartitions = Lists.partition(IdUuidPairs.uuids(analysisIdUuids), MAX_SNAPSHOTS_PER_QUERY); - deleteSnapshotDuplications(analysisUuidsPartitions); + deleteAnalysisDuplications(analysisUuidsPartitions); profiler.start("deleteAnalyses (events)"); - analysisUuidsPartitions.forEach(purgeMapper::deleteSnapshotEvents); + analysisUuidsPartitions.forEach(purgeMapper::deleteAnalysisEvents); session.commit(); profiler.stop(); @@ -209,7 +209,7 @@ class PurgeCommands { List> analysisIdsPartitions = Lists.partition(IdUuidPairs.ids(analysisUuids), MAX_SNAPSHOTS_PER_QUERY); List> analysisUuidsPartitions = Lists.partition(IdUuidPairs.uuids(analysisUuids), MAX_SNAPSHOTS_PER_QUERY); - deleteSnapshotDuplications(analysisUuidsPartitions); + deleteAnalysisDuplications(analysisUuidsPartitions); profiler.start("deleteSnapshotWastedMeasures (project_measures)"); List metricIdsWithoutHistoricalData = purgeMapper.selectMetricIdsWithoutHistoricalData(); @@ -226,9 +226,9 @@ class PurgeCommands { profiler.stop(); } - private void deleteSnapshotDuplications(List> snapshotUuidsPartitions) { - profiler.start("deleteSnapshotDuplications (duplications_index)"); - snapshotUuidsPartitions.forEach(purgeMapper::deleteSnapshotDuplications); + private void deleteAnalysisDuplications(List> snapshotUuidsPartitions) { + profiler.start("deleteAnalysisDuplications (duplications_index)"); + snapshotUuidsPartitions.forEach(purgeMapper::deleteAnalysisDuplications); session.commit(); profiler.stop(); } diff --git a/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java b/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java index a470b4d2dfd..20565364871 100644 --- a/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java +++ b/sonar-db/src/main/java/org/sonar/db/purge/PurgeDao.java @@ -186,7 +186,7 @@ public class PurgeDao implements Dao { executeLargeInputs(uuids, input -> { mapper.deleteResourceIndex(input); - mapper.setSnapshotIsLastToFalse(input); + mapper.setAnalysisIsLastToFalse(input); mapper.deleteFileSourcesByUuid(input); mapper.disableComponent(input); mapper.resolveComponentIssuesNotAlreadyResolved(input, system2.now()); diff --git a/sonar-db/src/main/java/org/sonar/db/purge/PurgeMapper.java b/sonar-db/src/main/java/org/sonar/db/purge/PurgeMapper.java index c58961f872e..fbfe594ab7c 100644 --- a/sonar-db/src/main/java/org/sonar/db/purge/PurgeMapper.java +++ b/sonar-db/src/main/java/org/sonar/db/purge/PurgeMapper.java @@ -26,7 +26,7 @@ import org.apache.ibatis.session.ResultHandler; public interface PurgeMapper { - List selectSnapshotIdsAndUuids(PurgeSnapshotQuery query); + List selectAnalysisIdsAndUuids(PurgeSnapshotQuery query); /** * Returns the list of components of a project from a project_uuid. The project itself is also returned. @@ -39,22 +39,19 @@ public interface PurgeMapper { void deleteDescendantSnapshots(@Param("snapshotIds") List snapshotIds); - void deleteSnapshot(@Param("snapshotUuids") List snapshotUuids); + void deleteAnalysisDuplications(@Param("analysisUuids") List analysisUuids); - void deleteSnapshotDuplications(@Param("analysisUuids") List analysisUuids); - - void deleteSnapshotEvents(@Param("analysisUuids") List analysisUuids); + void deleteAnalysisEvents(@Param("analysisUuids") List analysisUuids); void deleteAnalysisMeasures(@Param("analysisUuids") List analysisUuids); + // FIXME remove when snapshot cardinality is changed void deleteSnapshotMeasures(@Param("snapshotIds") List snapshotIds); void deleteComponentMeasures(@Param("analysisUuids") List analysisUuids, @Param("componentUuids") List componentUuids); List selectMetricIdsWithoutHistoricalData(); - void deleteSnapshotWastedMeasures(@Param("snapshotIds") List snapshotIds, @Param("mids") List metricIds); - void deleteAnalysisWastedMeasures(@Param("analysisUuids") List analysisUuids, @Param("metricIds") List metricIds); void updatePurgeStatusToOne(@Param("analysisUuids") List analysisUuid); @@ -67,7 +64,7 @@ public interface PurgeMapper { void deleteResourceIndex(@Param("componentUuids") List componentUuids); - void setSnapshotIsLastToFalse(@Param("componentUuids") List componentUuids); + void setAnalysisIsLastToFalse(@Param("componentUuids") List componentUuids); void deleteComponentLinks(@Param("componentUuids") List componentUuids); diff --git a/sonar-db/src/main/java/org/sonar/db/purge/PurgeSnapshotQuery.java b/sonar-db/src/main/java/org/sonar/db/purge/PurgeSnapshotQuery.java index c46d219c8db..27cb6c2768d 100644 --- a/sonar-db/src/main/java/org/sonar/db/purge/PurgeSnapshotQuery.java +++ b/sonar-db/src/main/java/org/sonar/db/purge/PurgeSnapshotQuery.java @@ -20,15 +20,12 @@ package org.sonar.db.purge; public final class PurgeSnapshotQuery { - private String snapshotUuid; - private String analysisUuid; private String rootComponentUuid; private String componentUuid; private String[] scopes; private String[] status; private Boolean islast; private Boolean notPurged; - private Boolean withVersionEvent; private PurgeSnapshotQuery() { } @@ -37,24 +34,6 @@ public final class PurgeSnapshotQuery { return new PurgeSnapshotQuery(); } - public String getSnapshotUuid() { - return snapshotUuid; - } - - public PurgeSnapshotQuery setSnapshotUuid(String snapshotUuid) { - this.snapshotUuid = snapshotUuid; - return this; - } - - public String getAnalysisUuid() { - return analysisUuid; - } - - public PurgeSnapshotQuery setAnalysisUuid(String analysisUuid) { - this.analysisUuid = analysisUuid; - return this; - } - public String getRootComponentUuid() { return rootComponentUuid; } @@ -109,12 +88,4 @@ public final class PurgeSnapshotQuery { return this; } - public Boolean getWithVersionEvent() { - return withVersionEvent; - } - - public PurgeSnapshotQuery setWithVersionEvent(Boolean withVersionEvent) { - this.withVersionEvent = withVersionEvent; - return this; - } } 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 8bd48191a83..c97dc468ad7 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 @@ -3,18 +3,12 @@ - select s.id as id, s.uuid as uuid from snapshots s - - join snapshots analysis on analysis.uuid=#{analysisUuid} and s.root_snapshot_id=analysis.id - - - and s.uuid=#{snapshotUuid} - and s.islast=#{islast} @@ -35,14 +29,6 @@ and s.scope in #{scope} - - - and exists(select e.id from events e where e.snapshot_id=s.id and e.category='Version') - - - and not exists(select e.id from events e where e.snapshot_id=s.id and e.category='Version') - - @@ -122,26 +108,21 @@ - - delete from duplications_index where analysis_uuid in - - #{analysisUuid} - - - - - delete from events where analysis_uuid in - - #{analysisUuid} - + + delete from duplications_index + where + analysis_uuid in + + #{analysisUuid} + - - delete from snapshots + + delete from events where - uuid in - - #{snapshotUuid} + analysis_uuid in + + #{analysisUuid} @@ -163,22 +144,6 @@ - - delete from project_measures - - snapshot_id in - - #{snapshotId} - - and (person_id is not null - - or metric_id in - #{mid} - - ) - - - delete from project_measures @@ -329,7 +294,7 @@ - + update snapshots set 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 d6df3980c36..393e0092aad 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 @@ -44,7 +44,7 @@ public class PurgeCommandsTest { public void shouldDeleteSnapshot() { dbTester.prepareDbUnit(getClass(), "shouldDeleteSnapshot.xml"); - new PurgeCommands(dbTester.getSession(), profiler).deleteSnapshots(PurgeSnapshotQuery.create().setSnapshotUuid("u5")); + new PurgeCommands(dbTester.getSession(), profiler).deleteSnapshots(PurgeSnapshotQuery.create().setComponentUuid("uuid_5")); dbTester.assertDbUnit(getClass(), "shouldDeleteSnapshot-result.xml", "snapshots", "project_measures", "duplications_index", "events"); } diff --git a/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java b/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java index 30e66d1f880..c8571441e03 100644 --- a/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java +++ b/sonar-db/src/test/java/org/sonar/db/purge/PurgeDaoTest.java @@ -103,24 +103,24 @@ public class PurgeDaoTest { } @Test - public void shouldDeleteSnapshots() { + public void shouldDeleteAnalyses() { dbTester.prepareDbUnit(getClass(), "shouldDeleteAnalyses.xml"); underTest.deleteAnalyses(dbSession, new PurgeProfiler(), ImmutableList.of(new IdUuidPair(3, "u3"))); dbTester.assertDbUnit(getClass(), "shouldDeleteAnalyses-result.xml", "snapshots"); } @Test - public void shouldSelectPurgeableSnapshots() { - dbTester.prepareDbUnit(getClass(), "shouldSelectPurgeableSnapshots.xml"); - List snapshots = underTest.selectPurgeableAnalyses(THE_PROJECT_UUID, dbSession); - - assertThat(snapshots).hasSize(3); - assertThat(getById(snapshots, "u1").isLast()).isTrue(); - assertThat(getById(snapshots, "u1").hasEvents()).isFalse(); - assertThat(getById(snapshots, "u4").isLast()).isFalse(); - assertThat(getById(snapshots, "u4").hasEvents()).isFalse(); - assertThat(getById(snapshots, "u5").isLast()).isFalse(); - assertThat(getById(snapshots, "u5").hasEvents()).isTrue(); + public void shouldSelectPurgeableAnalysis() { + dbTester.prepareDbUnit(getClass(), "shouldSelectPurgeableAnalysis.xml"); + List analyses = underTest.selectPurgeableAnalyses(THE_PROJECT_UUID, dbSession); + + assertThat(analyses).hasSize(3); + assertThat(getById(analyses, "u1").isLast()).isTrue(); + assertThat(getById(analyses, "u1").hasEvents()).isFalse(); + assertThat(getById(analyses, "u4").isLast()).isFalse(); + assertThat(getById(analyses, "u4").hasEvents()).isFalse(); + assertThat(getById(analyses, "u5").isLast()).isFalse(); + assertThat(getById(analyses, "u5").hasEvents()).isTrue(); } @Test diff --git a/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldSelectPurgeableSnapshots.xml b/sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldSelectPurgeableAnalysis.xml similarity index 100% rename from sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldSelectPurgeableSnapshots.xml rename to sonar-db/src/test/resources/org/sonar/db/purge/PurgeDaoTest/shouldSelectPurgeableAnalysis.xml -- 2.39.5