From: David Gageot Date: Sat, 6 Oct 2012 07:15:27 +0000 (+0200) Subject: SONAR-3641 Fix DBCleaner when there are 2000+ characteristics X-Git-Tag: 3.3~93 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8129e3c32539ebba359933d255190e765afe3ac7;p=sonarqube.git SONAR-3641 Fix DBCleaner when there are 2000+ characteristics --- diff --git a/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java b/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java index 7e670362182..9d3b77a486a 100644 --- a/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java +++ b/sonar-core/src/main/java/org/sonar/core/purge/PurgeCommands.java @@ -20,11 +20,14 @@ 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 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 ids : Iterables.partition(characteristicIds, MAX_CHARACTERISTICS_PER_QUERY)) { + purgeMapper.deleteSnapshotMeasuresOnCharacteristics(snapshotId, ids); + } } session.commit(); }