]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9350 delete components by project when deleting a project 2132/head
authorSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Wed, 31 May 2017 15:05:20 +0000 (17:05 +0200)
committerSébastien Lesaint <sebastien.lesaint@sonarsource.com>
Thu, 1 Jun 2017 13:20:16 +0000 (15:20 +0200)
works with views also, of course

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
server/sonar-db-dao/src/test/java/org/sonar/db/purge/PurgeCommandsTest.java

index 1c673d97846129fde19b9d87a0437f7d4b0a0541..8df3dfbc83b315da3903da3c85283d54e206acb8 100644 (file)
@@ -178,10 +178,9 @@ class PurgeCommands {
     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();
   }
index fdeafba33c2da8baafdcf32e3e6c2823a9ce17da..216a92217e1fc7941eeea0b63ffddf936585cf09 100644 (file)
@@ -153,7 +153,6 @@ public class PurgeDao implements Dao {
   }
 
   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))
@@ -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);
index e8e65b82cea318897183aa5730f65adc58846318..6889113e7ae2b81ffb7912d24b1c5ca3956a453d 100644 (file)
@@ -27,11 +27,6 @@ public interface PurgeMapper {
 
   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.
    */
@@ -59,7 +54,7 @@ public interface PurgeMapper {
 
   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);
 
index c1926a98446235522e98ee88667c252a951d2624..8f81562b9a6ced133f883c146e82047705dc55e6 100644 (file)
     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">
index 25c7ee39c21d6b885d385f78ad844da1d06bf6c7..81196f56e0b8cd848907093fb3911255f7a5d009 100644 (file)
@@ -86,7 +86,7 @@ public class PurgeCommandsTest {
     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);
@@ -182,23 +182,6 @@ public class PurgeCommandsTest {
     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++) {