profiler.stop();
List<List<String>> analysisUuidsPartitions = Lists.partition(IdUuidPairs.uuids(purgeMapper.selectAnalysisIdsAndUuids(new PurgeSnapshotQuery().setComponentUuid(rootUuid))),
- MAX_SNAPSHOTS_PER_QUERY);
+ MAX_SNAPSHOTS_PER_QUERY);
deleteAnalysisDuplications(analysisUuidsPartitions);
void deleteAnalyses(PurgeSnapshotQuery... queries) {
List<IdUuidPair> snapshotIds = from(asList(queries))
- .transformAndConcat(purgeMapper::selectAnalysisIdsAndUuids)
- .toList();
+ .transformAndConcat(purgeMapper::selectAnalysisIdsAndUuids)
+ .toList();
deleteAnalyses(snapshotIds);
}
profiler.start("deleteSnapshotWastedMeasures (project_measures)");
List<Long> metricIdsWithoutHistoricalData = purgeMapper.selectMetricIdsWithoutHistoricalData();
analysisUuidsPartitions
- .forEach(analysisUuidsPartition -> purgeMapper.deleteAnalysisWastedMeasures(analysisUuidsPartition, metricIdsWithoutHistoricalData));
+ .forEach(analysisUuidsPartition -> purgeMapper.deleteAnalysisWastedMeasures(analysisUuidsPartition, metricIdsWithoutHistoricalData));
session.commit();
profiler.stop();
profiler.stop();
}
+ void deleteIssues(String rootUuid) {
+ profiler.start("deleteIssues (issue_changes)");
+ purgeMapper.deleteComponentIssueChanges(rootUuid);
+ session.commit();
+ profiler.stop();
+
+ profiler.start("deleteIssues (issues)");
+ purgeMapper.deleteComponentIssues(rootUuid);
+ session.commit();
+ profiler.stop();
+ }
+
void deleteComponents(List<IdUuidPair> componentIdUuids) {
List<List<Long>> componentIdPartitions = Lists.partition(IdUuidPairs.ids(componentIdUuids), MAX_RESOURCES_PER_QUERY);
List<List<String>> componentUuidsPartitions = Lists.partition(IdUuidPairs.uuids(componentIdUuids), MAX_RESOURCES_PER_QUERY);
session.commit();
profiler.stop();
- profiler.start("deleteComponentIssueChanges (issue_changes)");
- componentUuidsPartitions.forEach(purgeMapper::deleteComponentIssueChanges);
- session.commit();
- profiler.stop();
-
- profiler.start("deleteComponentIssues (issues)");
- componentUuidsPartitions.forEach(purgeMapper::deleteComponentIssues);
- session.commit();
- profiler.stop();
-
profiler.start("deleteResource (projects)");
componentUuidsPartitions.forEach(purgeMapper::deleteComponents);
session.commit();
commands.deletePermissions(rootId);
commands.deleteAnalyses(rootUuid);
commands.deleteComponents(childrenIds);
+ commands.deleteIssues(rootUuid);
commands.deleteFileSources(rootUuid);
commands.deleteCeActivity(rootUuid);
commands.deleteCeQueue(rootUuid);
List<PurgeableAnalysisDto> selectPurgeableAnalysesWithoutEvents(@Param("componentUuid") String componentUuid);
- void deleteComponentIssueChanges(@Param("componentUuids") List<String> componentUuids);
+ void deleteComponentIssueChanges(@Param("rootUuid") String rootUuid);
- void deleteComponentIssues(@Param("componentUuids") List<String> componentUuids);
+ void deleteComponentIssues(@Param("rootUuid") String rootUuid);
List<String> selectOldClosedIssueKeys(@Param("projectUuid") String projectUuid, @Nullable @Param("toDate") Long toDate);
<delete id="deleteComponentIssueChanges" parameterType="map">
delete from issue_changes ic
- where exists (select * from issues i where i.kee=ic.issue_key and i.component_uuid in
- <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
- #{componentUuid,jdbcType=VARCHAR}
- </foreach>
- )
+ where
+ exists (select 1 from issues i where i.kee=ic.issue_key and i.project_uuid = #{rootUuid,jdbcType=VARCHAR})
</delete>
<!-- Mssql -->
<delete id="deleteComponentIssueChanges" databaseId="mssql" parameterType="map">
delete issue_changes from issue_changes
- inner join issues on issue_changes.issue_key=issues.kee
- where issues.component_uuid in
- <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
- #{componentUuid,jdbcType=VARCHAR}
- </foreach>
+ inner join issues on
+ issue_changes.issue_key=issues.kee
+ where
+ issues.project_uuid = #{rootUuid,jdbcType=VARCHAR}
</delete>
<!-- Mysql -->
<delete id="deleteComponentIssueChanges" databaseId="mysql" parameterType="map">
- delete ic from issue_changes as ic, issues as i where ic.issue_key=i.kee and i.component_uuid in
- <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
- #{componentUuid,jdbcType=VARCHAR}
- </foreach>
+ delete ic from issue_changes as ic, issues as i
+ where
+ ic.issue_key=i.kee
+ and i.component_uuid = #{rootUuid,jdbcType=VARCHAR}
</delete>
<delete id="deleteComponentIssues" parameterType="map">
- delete from issues where component_uuid in
- <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
- #{componentUuid,jdbcType=VARCHAR}
- </foreach>
+ delete from issues
+ where project_uuid = #{rootUuid,jdbcType=VARCHAR}
</delete>
<delete id="deleteFileSourcesByProjectUuid">
assertThat(dbTester.countRowsOfTable("projects")).isZero();
assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(1);
assertThat(dbTester.countRowsOfTable("events")).isEqualTo(3);
- assertThat(dbTester.countRowsOfTable("issues")).isZero();
- assertThat(dbTester.countRowsOfTable("issue_changes")).isZero();
+ assertThat(dbTester.countRowsOfTable("issues")).isEqualTo(1);
+ assertThat(dbTester.countRowsOfTable("issue_changes")).isEqualTo(1);
}
assertThat(dbTester.countRowsOfTable("projects")).isEqualTo(1);
assertThat(dbTester.countRowsOfTable("snapshots")).isZero();
- assertThat(dbTester.countRowsOfTable("events")).isEqualTo(0);
+ assertThat(dbTester.countRowsOfTable("events")).isZero();
assertThat(dbTester.countRowsOfTable("issues")).isEqualTo(1);
assertThat(dbTester.countRowsOfTable("issue_changes")).isEqualTo(1);
}
+
+ @Test
+ public void shouldDeleteIssuesAndIssueChanges() {
+ dbTester.prepareDbUnit(getClass(), "shouldDeleteResource.xml");
+
+ PurgeCommands purgeCommands = new PurgeCommands(dbTester.getSession(), profiler);
+ purgeCommands.deleteIssues("uuid_1");
+
+ assertThat(dbTester.countRowsOfTable("projects")).isEqualTo(1);
+ assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(1);
+ assertThat(dbTester.countRowsOfTable("events")).isEqualTo(3);
+ assertThat(dbTester.countRowsOfTable("issues")).isZero();
+ assertThat(dbTester.countRowsOfTable("issue_changes")).isZero();
+ }
+
@Test
public void deletePermissions_deletes_permissions_of_public_project() {
OrganizationDto organization = dbTester.organizations().insert();
<issues id="1"
kee="ABCDE"
component_uuid="uuid_1"
- project_uuid="1"
+ project_uuid="uuid_1"
status="CLOSED"
resolution="[null]"
line="200"