profiler.stop();
}
- void deleteComponents(List<IdUuidPair> componentIdUuids) {
- List<List<String>> componentUuidsPartitions = Lists.partition(IdUuidPairs.uuids(componentIdUuids), MAX_RESOURCES_PER_QUERY);
+ void deleteComponents(String rootUuid) {
profiler.start("deleteComponents (projects)");
- componentUuidsPartitions.forEach(purgeMapper::deleteComponents);
+ purgeMapper.deleteComponents(rootUuid);
session.commit();
profiler.stop();
}
}
private static void deleteProject(String rootUuid, PurgeMapper mapper, PurgeCommands commands) {
- List<IdUuidPair> componentsIds = mapper.selectComponentsByProjectUuid(rootUuid);
List<IdUuidPair> rootAndModulesOrSubviews = mapper.selectRootAndModulesOrSubviewsByProjectUuid(rootUuid);
long rootId = rootAndModulesOrSubviews.stream()
.filter(pair -> pair.getUuid().equals(rootUuid))
commands.deleteLinks(rootUuid);
commands.deleteAnalyses(rootUuid);
commands.deleteByRootAndModulesOrSubviews(rootAndModulesOrSubviews);
- commands.deleteComponents(componentsIds);
+ commands.deleteComponents(rootUuid);
commands.deleteIssues(rootUuid);
commands.deleteFileSources(rootUuid);
commands.deleteCeActivity(rootUuid);
List<IdUuidPair> selectAnalysisIdsAndUuids(PurgeSnapshotQuery query);
- /**
- * Returns the list of components of a project from a project_uuid. The project itself is also returned.
- */
- List<IdUuidPair> selectComponentsByProjectUuid(String projectUuid);
-
/**
* Returns the list of modules/subviews and the view/project for the specified project_uuid.
*/
void deleteComponentProperties(@Param("componentIds") List<Long> componentIds);
- void deleteComponents(@Param("componentUuids") List<String> componentUuids);
+ void deleteComponents(@Param("rootUuid") String rootUuid);
void deleteComponentGroupRoles(@Param("rootId") long rootId);
select id from metrics where delete_historical_data=${_true}
</select>
- <select id="selectComponentsByProjectUuid" resultType="org.sonar.db.purge.IdUuidPair" parameterType="String">
- select id, uuid from projects where project_uuid=#{uuid,jdbcType=VARCHAR} or uuid=#{uuid,jdbcType=VARCHAR}
- </select>
-
<select id="selectRootAndModulesOrSubviewsByProjectUuid" resultType="org.sonar.db.purge.IdUuidPair" parameterType="String">
select
p.id, p.uuid
<delete id="deleteComponents" parameterType="map">
delete from projects
where
- uuid in
- <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
- #{componentUuid,jdbcType=VARCHAR}
- </foreach>
+ project_uuid = #{rootUuid,jdbcType=VARCHAR}
</delete>
<delete id="deleteComponentGroupRoles" parameterType="map">
dbTester.prepareDbUnit(getClass(), "shouldDeleteResource.xml");
PurgeCommands purgeCommands = new PurgeCommands(dbTester.getSession(), profiler);
- purgeCommands.deleteComponents(newArrayList(new IdUuidPair(1L, "uuid_1")));
+ purgeCommands.deleteComponents("uuid_1");
assertThat(dbTester.countRowsOfTable("projects")).isZero();
assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(1);
assertThat(dbTester.countRowsOfTable("user_roles")).isEqualTo(2);
}
- /**
- * 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_resources() {
- new PurgeCommands(dbTester.getSession(), profiler).deleteComponents(getHugeNumberOfIdUuids());
- // The goal of this test is only to check that the query do no fail, not to check result
- }
-
- private List<IdUuidPair> getHugeNumberOfIdUuids() {
- List<IdUuidPair> hugeNbOfSnapshotIds = newArrayList();
- for (long i = 0; i < 4500; i++) {
- hugeNbOfSnapshotIds.add(new IdUuidPair(i, String.valueOf(i)));
- }
- return hugeNbOfSnapshotIds;
- }
-
private List<IdUuidPair> getHugeNumberOfIdUuidPairs() {
List<IdUuidPair> hugeNbOfSnapshotIds = newArrayList();
for (long i = 0; i < 4500; i++) {