]> source.dussan.org Git - sonarqube.git/commitdiff
Execute purge on wasted measures even of there's no measure on metrics without histor...
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 11 Mar 2014 09:57:02 +0000 (10:57 +0100)
committerJulien Lancelot <julien.lancelot@sonarsource.com>
Tue, 11 Mar 2014 09:57:02 +0000 (10:57 +0100)
sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java
sonar-core/src/main/resources/org/sonar/core/purge/PurgeMapper.xml
sonar-core/src/test/java/org/sonar/core/purge/PurgeCommandsTest.java

index f2be30838c3abed9aac109eeb276f46e14a1b757..da4451e627aa01f1b6d7183e93dc03108dd128c7 100644 (file)
@@ -222,12 +222,10 @@ class PurgeCommands {
 
     profiler.start("deleteSnapshotWastedMeasures (project_measures)");
     List<Long> metricIdsWithoutHistoricalData = purgeMapper.selectMetricIdsWithoutHistoricalData();
-    if (!metricIdsWithoutHistoricalData.isEmpty()) {
-      for (List<Long> partSnapshotIds : snapshotIdsPartition) {
-        purgeMapper.deleteSnapshotWastedMeasures(partSnapshotIds, metricIdsWithoutHistoricalData);
-      }
-      session.commit();
+    for (List<Long> partSnapshotIds : snapshotIdsPartition) {
+      purgeMapper.deleteSnapshotWastedMeasures(partSnapshotIds, metricIdsWithoutHistoricalData);
     }
+    session.commit();
     profiler.stop();
 
     profiler.start("updatePurgeStatusToOne (snapshots)");
index a6f3ab5a38bebf68e0761932278cd583c38865e4..a7de12225bb11842d83232ef71da34d8ef75d392 100644 (file)
   </delete>
 
   <delete id="deleteSnapshotWastedMeasures" parameterType="map">
-    delete from project_measures where snapshot_id in
+    delete from project_measures
+    <where>
+    snapshot_id in
     <foreach collection="snapshotIds" open="(" close=")" item="snapshotId" separator=",">
         #{snapshotId}
     </foreach>
-    and
-    (rule_id is not null or person_id is not null or metric_id in
-    <foreach item="mid" index="index" collection="mids" open="(" separator="," close=")">#{mid}</foreach>
-    )
+    and (rule_id is not null or person_id is not null
+    <if test="mids.size()>0">
+      or metric_id in
+      <foreach item="mid" index="index" collection="mids" open="(" separator="," close=")">#{mid}</foreach>
+    </if>)
+    </where>
   </delete>
 
   <update id="updatePurgeStatusToOne" parameterType="long">
index de1f6b5d4c6d9ca529ff80c63f9fe799bc68dcb6..347ea4dc81c5bcaf0b4623dd9503d59738a3d16f 100644 (file)
@@ -88,7 +88,7 @@ public class PurgeCommandsTest extends AbstractDaoTestCase {
   }
 
   @Test
-  public void shouldDeleteWastedMeasuresWhenPurgingSnapshot() {
+  public void delete_wasted_measures_when_purging_snapshot() {
     setupData("shouldDeleteWastedMeasuresWhenPurgingSnapshot");
 
     SqlSession session = getMyBatis().openSession();