]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9346 delete links by project when deleting project
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Tue, 30 May 2017 10:18:34 +0000 (12:18 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 1 Jun 2017 13:18:55 +0000 (15:18 +0200)
server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java
server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java
server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java
server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml

index d57990db4bf8fc4754077b66feab704d2bb8b920..d3ed34b2cdc954c3726dd193e9c4074ceb186788 100644 (file)
@@ -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<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);
@@ -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();
index 1e804170efda21eeb2729ba279638af2b3fd9f27..c7ee2fc5e9e59c82b108503cdf425f5e489bcd29 100644 (file)
@@ -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);
index f860348e6e8e52d493d40b3c697aae277a1d5f02..71f4d1afc6760c44bad03a3185946fc3dfeb65ad 100644 (file)
@@ -50,7 +50,7 @@ public interface PurgeMapper {
 
   void resolveComponentIssuesNotAlreadyResolved(@Param("componentUuids") List<String> componentUuids, @Param("dateAsLong") Long dateAsLong);
 
-  void deleteComponentLinks(@Param("componentUuids") List<String> componentUuids);
+  void deleteComponentLinks(@Param("rootUuid") String rootUuid);
 
   void deleteComponentProperties(@Param("componentIds") List<Long> componentIds);
 
index 7a93f7136be35e0a7c22722aa1b2b7a0efd4ad32..a2d461853e097167458df9138138dd44078d520d 100644 (file)
   <delete id="deleteComponentLinks" parameterType="map">
     delete from project_links
     where
-      component_uuid in
-      <foreach collection="componentUuids" open="(" close=")" item="componentUuid" separator=",">
-        #{componentUuid,jdbcType=VARCHAR}
-      </foreach>
+      component_uuid = #{rootUuid,jdbcType=VARCHAR}
   </delete>
 
   <delete id="deleteComponentProperties" parameterType="map">