From 8129e3c32539ebba359933d255190e765afe3ac7 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Sat, 6 Oct 2012 09:15:27 +0200 Subject: [PATCH] SONAR-3641 Fix DBCleaner when there are 2000+ characteristics --- .../src/main/java/org/sonar/core/purge/PurgeCommands.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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(); } -- 2.39.5