]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-3641 Fix DBCleaner when there are 2000+ characteristics
authorDavid Gageot <david@gageot.net>
Sat, 6 Oct 2012 07:15:27 +0000 (09:15 +0200)
committerDavid Gageot <david@gageot.net>
Sat, 6 Oct 2012 07:15:27 +0000 (09:15 +0200)
sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java

index 7e670362182923a72bf0721a5fad02c6d315010f..9d3b77a486a7e87bcc615a79b04c7f8f2c557a04 100644 (file)
 package org.sonar.core.purge;
 
 import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.Iterables;
 import org.apache.ibatis.session.SqlSession;
 
 import java.util.List;
 
 class PurgeCommands {
+  private static final int MAX_CHARACTERISTICS_PER_QUERY = 1000;
+
   private final SqlSession session;
   private final PurgeMapper purgeMapper;
 
@@ -203,7 +206,10 @@ class PurgeCommands {
     List<Long> characteristicIds = purgeMapper.selectCharacteristicIdsToPurge();
     if (!characteristicIds.isEmpty()) {
       for (Long snapshotId : snapshotIds) {
-        purgeMapper.deleteSnapshotMeasuresOnCharacteristics(snapshotId, characteristicIds);
+        // SONAR-3641 We cannot process all characteristics at once
+        for (List<Long> ids : Iterables.partition(characteristicIds, MAX_CHARACTERISTICS_PER_QUERY)) {
+          purgeMapper.deleteSnapshotMeasuresOnCharacteristics(snapshotId, ids);
+        }
       }
       session.commit();
     }