public void deleteAnalyses(DbSession session, PurgeProfiler profiler, List<IdUuidPair> analysisIdUuids) { new PurgeCommands(session, profiler).deleteAnalyses(analysisIdUuids); }
private static void deleteRootComponent(String rootUuid, PurgeMapper mapper, PurgeCommands commands) { List<IdUuidPair> rootAndModulesOrSubviews = mapper.selectRootAndModulesOrSubviewsByProjectUuid(rootUuid); long rootId = rootAndModulesOrSubviews.stream() .filter(pair -> pair.getUuid().equals(rootUuid)) .map(IdUuidPair::getId) .findFirst() .orElseThrow(() -> new IllegalArgumentException("Couldn't find root component with uuid " + rootUuid)); commands.deletePermissions(rootId); commands.deleteLinks(rootUuid); commands.deleteAnalyses(rootUuid); commands.deleteByRootAndModulesOrSubviews(rootAndModulesOrSubviews); commands.deleteComponents(rootUuid); commands.deleteIssues(rootUuid); commands.deleteFileSources(rootUuid); commands.deleteCeActivity(rootUuid); commands.deleteCeQueue(rootUuid); commands.deleteWebhooks(rootUuid); commands.deleteWebhookDeliveries(rootUuid); commands.deleteProjectMappings(rootUuid); commands.deleteProjectAlmBindings(rootUuid); commands.deleteBranch(rootUuid); commands.deleteLiveMeasures(rootUuid); }
/** * Test that SQL queries execution do not fail with a huge number of parameter */ @Test public void should_not_fail_when_purging_huge_number_of_analyses() { new PurgeCommands(dbTester.getSession(), profiler).purgeAnalyses(getHugeNumberOfIdUuidPairs()); // The goal of this test is only to check that the query do no fail, not to check result }
private static void deleteNonRootComponentsInView(Set<ComponentDto> nonRootComponents, PurgeCommands purgeCommands) { List<IdUuidPair> subviewsOrProjectCopies = nonRootComponents.stream() .filter(PurgeDao::isModuleOrSubview) .map(PurgeDao::toIdUuidPair) .collect(MoreCollectors.toList()); purgeCommands.deleteByRootAndModulesOrSubviews(subviewsOrProjectCopies); List<String> nonRootComponentUuids = nonRootComponents.stream().map(ComponentDto::uuid).collect(MoreCollectors.toList(nonRootComponents.size())); purgeCommands.deleteComponentMeasures(nonRootComponentUuids); purgeCommands.deleteComponents(nonRootComponentUuids); }
private static void deleteProject(String rootUuid, PurgeMapper mapper, PurgeCommands commands) { List<IdUuidPair> childrenIds = mapper.selectComponentsByProjectUuid(rootUuid); commands.deleteAnalyses(rootUuid); commands.deleteComponents(childrenIds); commands.deleteFileSources(rootUuid); commands.deleteCeActivity(rootUuid); commands.deleteWebhookDeliveries(rootUuid); }
@Test public void deletePermissions_deletes_permissions_of_public_project() { OrganizationDto organization = dbTester.organizations().insert(); ComponentDto project = dbTester.components().insertPublicProject(organization); addPermissions(organization, project); PurgeCommands purgeCommands = new PurgeCommands(dbTester.getSession(), profiler); purgeCommands.deletePermissions(project.getId()); assertThat(dbTester.countRowsOfTable("group_roles")).isEqualTo(2); assertThat(dbTester.countRowsOfTable("user_roles")).isEqualTo(1); }
/** * Delete the non root components (ie. sub-view, application or project copy) from the specified collection of {@link ComponentDto} * and data from their child tables. * <p> * This method has no effect when passed an empty collection or only root components. * </p> */ public void deleteNonRootComponentsInView(DbSession dbSession, Collection<ComponentDto> components) { Set<ComponentDto> nonRootComponents = components.stream().filter(PurgeDao::isNotRoot).collect(MoreCollectors.toSet()); if (nonRootComponents.isEmpty()) { return; } PurgeProfiler profiler = new PurgeProfiler(); PurgeCommands purgeCommands = new PurgeCommands(dbSession, profiler); deleteNonRootComponentsInView(nonRootComponents, purgeCommands); }
private static void purgeAnalyses(PurgeCommands commands, String rootUuid) { List<IdUuidPair> analysisUuids = commands.selectSnapshotIdUuids( new PurgeSnapshotQuery() .setComponentUuid(rootUuid) .setIslast(false) .setNotPurged(true)); commands.purgeAnalyses(analysisUuids); }
@Test public void shouldDeleteComponentsAndChildrenTables() { dbTester.prepareDbUnit(getClass(), "shouldDeleteResource.xml"); PurgeCommands purgeCommands = new PurgeCommands(dbTester.getSession(), profiler); purgeCommands.deleteComponents("uuid_1"); assertThat(dbTester.countRowsOfTable("projects")).isZero(); assertThat(dbTester.countRowsOfTable("snapshots")).isEqualTo(1); assertThat(dbTester.countRowsOfTable("events")).isEqualTo(3); assertThat(dbTester.countRowsOfTable("issues")).isEqualTo(1); assertThat(dbTester.countRowsOfTable("issue_changes")).isEqualTo(1); }
void deleteAnalyses(PurgeSnapshotQuery... queries) { List<IdUuidPair> snapshotIds = Arrays.stream(queries) .flatMap(q -> purgeMapper.selectAnalysisIdsAndUuids(q).stream()) .collect(Collectors.toList()); deleteAnalyses(snapshotIds); }
private void deleteDataOfComponentsWithoutHistoricalData(DbSession dbSession, String rootUuid, Collection<String> scopesWithoutHistoricalData, PurgeCommands purgeCommands) { if (scopesWithoutHistoricalData.isEmpty()) { return; } List<String> analysisUuids = purgeCommands.selectSnapshotUuids( new PurgeSnapshotQuery() .setComponentUuid(rootUuid) .setIslast(false) .setNotPurged(true)); List<String> componentWithoutHistoricalDataUuids = componentDao .selectDescendants( dbSession, ComponentTreeQuery.builder() .setBaseUuid(rootUuid) .setScopes(scopesWithoutHistoricalData) .setStrategy(Strategy.LEAVES) .build()) .stream().map(ComponentDto::uuid) .collect(MoreCollectors.toList()); purgeCommands.deleteComponentMeasures(analysisUuids, componentWithoutHistoricalDataUuids); }
@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(); }
void purgeAnalyses(List<IdUuidPair> analysisUuids) { List<List<String>> analysisUuidsPartitions = Lists.partition(IdUuidPairs.uuids(analysisUuids), MAX_SNAPSHOTS_PER_QUERY); deleteAnalysisDuplications(analysisUuidsPartitions); profiler.start("deleteSnapshotWastedMeasures (project_measures)"); List<Long> metricIdsWithoutHistoricalData = purgeMapper.selectMetricIdsWithoutHistoricalData(); if (!metricIdsWithoutHistoricalData.isEmpty()) { analysisUuidsPartitions .forEach(analysisUuidsPartition -> purgeMapper.deleteAnalysisWastedMeasures(analysisUuidsPartition, metricIdsWithoutHistoricalData)); session.commit(); } profiler.stop(); profiler.start("updatePurgeStatusToOne (snapshots)"); analysisUuidsPartitions.forEach(purgeMapper::updatePurgeStatusToOne); session.commit(); profiler.stop(); }
@Test public void deletePermissions_deletes_permissions_of_private_project() { OrganizationDto organization = dbTester.organizations().insert(); ComponentDto project = dbTester.components().insertPrivateProject(organization); addPermissions(organization, project); PurgeCommands purgeCommands = new PurgeCommands(dbTester.getSession(), profiler); purgeCommands.deletePermissions(project.getId()); assertThat(dbTester.countRowsOfTable("group_roles")).isEqualTo(1); assertThat(dbTester.countRowsOfTable("user_roles")).isEqualTo(1); }
public void deleteBranch(DbSession session, String uuid) { PurgeProfiler profiler = new PurgeProfiler(); PurgeMapper purgeMapper = mapper(session); PurgeCommands purgeCommands = new PurgeCommands(session, profiler); deleteRootComponent(uuid, purgeMapper, purgeCommands); }
private static void purgeAnalyses(PurgeCommands commands, String rootUuid) { List<IdUuidPair> analysisUuids = commands.selectSnapshotIdUuids( new PurgeSnapshotQuery() .setComponentUuid(rootUuid) .setIslast(false) .setNotPurged(true)); commands.purgeAnalyses(analysisUuids); }
private static void deleteAbortedAnalyses(String rootUuid, PurgeCommands commands) { LOG.debug("<- Delete aborted builds"); PurgeSnapshotQuery query = new PurgeSnapshotQuery() .setIslast(false) .setStatus(UNPROCESSED_STATUS) .setComponentUuid(rootUuid); commands.deleteAnalyses(query); }
private void deleteDataOfComponentsWithoutHistoricalData(DbSession dbSession, String rootUuid, String[] scopesWithoutHistoricalData, PurgeCommands purgeCommands) { if (scopesWithoutHistoricalData.length == 0) { return; } List<String> analysisUuids = purgeCommands.selectSnapshotUuids( new PurgeSnapshotQuery() .setComponentUuid(rootUuid) .setIslast(false) .setNotPurged(true)); List<String> componentWithoutHistoricalDataUuids = componentDao .selectDescendants( dbSession, ComponentTreeQuery.builder() .setBaseUuid(rootUuid) .setQualifiers(Arrays.asList(scopesWithoutHistoricalData)) .setStrategy(Strategy.LEAVES) .build()) .stream().map(ComponentDto::uuid) .collect(Collectors.toList()); purgeCommands.deleteComponentMeasures(analysisUuids, componentWithoutHistoricalDataUuids); }
@VisibleForTesting void deleteAnalyses(List<IdUuidPair> analysisIdUuids) { List<List<String>> analysisUuidsPartitions = Lists.partition(IdUuidPairs.uuids(analysisIdUuids), MAX_SNAPSHOTS_PER_QUERY); deleteAnalysisDuplications(analysisUuidsPartitions); profiler.start("deleteAnalyses (event_component_changes)"); analysisUuidsPartitions.forEach(purgeMapper::deleteAnalysisEventComponentChanges); session.commit(); profiler.stop(); profiler.start("deleteAnalyses (events)"); analysisUuidsPartitions.forEach(purgeMapper::deleteAnalysisEvents); session.commit(); profiler.stop(); profiler.start("deleteAnalyses (project_measures)"); analysisUuidsPartitions.forEach(purgeMapper::deleteAnalysisMeasures); session.commit(); profiler.stop(); profiler.start("deleteAnalyses (snapshots)"); analysisUuidsPartitions.forEach(purgeMapper::deleteAnalyses); session.commit(); profiler.stop(); profiler.start("deleteAnalyses (analysis_properties)"); analysisUuidsPartitions.forEach(purgeMapper::deleteAnalysisProperties); session.commit(); profiler.stop(); }
/** * 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 }