From abedc4c0f77c3885abd0026a8e5db5f2c454dfaa Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Wed, 31 May 2017 17:05:20 +0200 Subject: [PATCH] SONAR-9350 delete components by project when deleting a project works with views also, of course --- .../org/sonar/db/purge/PurgeCommands.java | 5 ++--- .../java/org/sonar/db/purge/PurgeDao.java | 3 +-- .../java/org/sonar/db/purge/PurgeMapper.java | 7 +------ .../org/sonar/db/purge/PurgeMapper.xml | 9 +-------- .../org/sonar/db/purge/PurgeCommandsTest.java | 19 +------------------ 5 files changed, 6 insertions(+), 37 deletions(-) diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java index 1c673d97846..8df3dfbc83b 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java @@ -178,10 +178,9 @@ class PurgeCommands { profiler.stop(); } - void deleteComponents(List componentIdUuids) { - List> 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(); } diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java index fdeafba33c2..216a92217e1 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java @@ -153,7 +153,6 @@ public class PurgeDao implements Dao { } private static void deleteProject(String rootUuid, PurgeMapper mapper, PurgeCommands commands) { - List componentsIds = mapper.selectComponentsByProjectUuid(rootUuid); List rootAndModulesOrSubviews = mapper.selectRootAndModulesOrSubviewsByProjectUuid(rootUuid); long rootId = rootAndModulesOrSubviews.stream() .filter(pair -> pair.getUuid().equals(rootUuid)) @@ -164,7 +163,7 @@ public class PurgeDao implements Dao { commands.deleteLinks(rootUuid); commands.deleteAnalyses(rootUuid); commands.deleteByRootAndModulesOrSubviews(rootAndModulesOrSubviews); - commands.deleteComponents(componentsIds); + commands.deleteComponents(rootUuid); commands.deleteIssues(rootUuid); commands.deleteFileSources(rootUuid); commands.deleteCeActivity(rootUuid); diff --git a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java index e8e65b82cea..6889113e7ae 100644 --- a/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java +++ b/server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java @@ -27,11 +27,6 @@ public interface PurgeMapper { List selectAnalysisIdsAndUuids(PurgeSnapshotQuery query); - /** - * Returns the list of components of a project from a project_uuid. The project itself is also returned. - */ - List selectComponentsByProjectUuid(String projectUuid); - /** * Returns the list of modules/subviews and the view/project for the specified project_uuid. */ @@ -59,7 +54,7 @@ public interface PurgeMapper { void deleteComponentProperties(@Param("componentIds") List componentIds); - void deleteComponents(@Param("componentUuids") List componentUuids); + void deleteComponents(@Param("rootUuid") String rootUuid); void deleteComponentGroupRoles(@Param("rootId") long rootId); diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml index c1926a98446..8f81562b9a6 100644 --- a/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml +++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml @@ -51,10 +51,6 @@ select id from metrics where delete_historical_data=${_true} - -