From cfa1b2e92b7cf94e661653fb1dd233e744d02da3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?S=C3=A9bastien=20Lesaint?= Date: Tue, 30 May 2017 12:18:34 +0200 Subject: [PATCH] SONAR-9346 delete links by project when deleting project --- .../main/java/org/sonar/db/purge/PurgeCommands.java | 12 +++++++----- .../src/main/java/org/sonar/db/purge/PurgeDao.java | 1 + .../main/java/org/sonar/db/purge/PurgeMapper.java | 2 +- .../resources/org/sonar/db/purge/PurgeMapper.xml | 5 +---- 4 files changed, 10 insertions(+), 10 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 d57990db4bf..d3ed34b2cdc 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 @@ -156,6 +156,13 @@ class PurgeCommands { profiler.stop(); } + void deleteLinks(String rootUuid) { + profiler.start("deleteLinks (project_links)"); + purgeMapper.deleteComponentLinks(rootUuid); + session.commit(); + profiler.stop(); + } + void deleteComponents(List componentIdUuids) { List> componentIdPartitions = Lists.partition(IdUuidPairs.ids(componentIdUuids), MAX_RESOURCES_PER_QUERY); List> componentUuidsPartitions = Lists.partition(IdUuidPairs.uuids(componentIdUuids), MAX_RESOURCES_PER_QUERY); @@ -165,11 +172,6 @@ class PurgeCommands { // possible missing optimization: filter requests according to resource scope - profiler.start("deleteResourceLinks (project_links)"); - componentUuidsPartitions.forEach(purgeMapper::deleteComponentLinks); - session.commit(); - profiler.stop(); - profiler.start("deleteResourceProperties (properties)"); componentIdPartitions.forEach(purgeMapper::deleteComponentProperties); session.commit(); 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 1e804170efd..c7ee2fc5e9e 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 @@ -160,6 +160,7 @@ public class PurgeDao implements Dao { .findFirst() .orElseThrow(() -> new IllegalStateException("Couldn't find component for root uuid " + rootUuid)); commands.deletePermissions(rootId); + commands.deleteLinks(rootUuid); commands.deleteAnalyses(rootUuid); commands.deleteComponents(childrenIds); commands.deleteIssues(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 f860348e6e8..71f4d1afc67 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 @@ -50,7 +50,7 @@ public interface PurgeMapper { void resolveComponentIssuesNotAlreadyResolved(@Param("componentUuids") List componentUuids, @Param("dateAsLong") Long dateAsLong); - void deleteComponentLinks(@Param("componentUuids") List componentUuids); + void deleteComponentLinks(@Param("rootUuid") String rootUuid); void deleteComponentProperties(@Param("componentIds") List componentIds); 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 7a93f7136be..a2d461853e0 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 @@ -154,10 +154,7 @@ delete from project_links where - component_uuid in - - #{componentUuid,jdbcType=VARCHAR} - + component_uuid = #{rootUuid,jdbcType=VARCHAR} -- 2.39.5