package org.sonar.core.purge;
import com.google.common.annotations.VisibleForTesting;
-import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import org.apache.ibatis.session.SqlSession;
import java.util.List;
class PurgeCommands {
- private static final int MAX_CHARACTERISTICS_PER_QUERY = 1000;
+
private static final int MAX_SNAPSHOTS_PER_QUERY = 1000;
private static final int MAX_RESOURCES_PER_QUERY = 1000;
}
profiler.stop();
- profiler.start("deleteSnapshotMeasuresOnCharacteristics (project_measures)");
- List<Long> characteristicIds = purgeMapper.selectCharacteristicIdsToPurge();
- if (!characteristicIds.isEmpty()) {
- for (List<Long> partSnapshotIds : snapshotIdsPartition) {
- // SONAR-3641 We cannot process all characteristics at once
- for (List<Long> ids : Iterables.partition(characteristicIds, MAX_CHARACTERISTICS_PER_QUERY)) {
- purgeMapper.deleteSnapshotMeasuresOnCharacteristics(partSnapshotIds, ids);
- }
- }
- session.commit();
- }
- profiler.stop();
-
profiler.start("updatePurgeStatusToOne (snapshots)");
for (Long snapshotId : snapshotIds) {
purgeMapper.updatePurgeStatusToOne(snapshotId);
select id from metrics where delete_historical_data=${_true}
</select>
- <select id="selectCharacteristicIdsToPurge" resultType="long">
- select id from characteristics where rule_id is not null
- </select>
-
<select id="selectProjectIdsByRootId" resultType="long" parameterType="long">
select id from projects where root_id=#{id} and scope='PRJ'
</select>
)
</delete>
- <delete id="deleteSnapshotMeasuresOnCharacteristics" parameterType="map">
- delete from project_measures where snapshot_id in
- <foreach collection="snapshotIds" open="(" close=")" item="snapshotId" separator=",">
- #{snapshotId}
- </foreach>
- and (
- <foreach item="cid" index="index" collection="cids" open="" separator=" OR " close="">characteristic_id=#{cid}</foreach>
- )
- </delete>
-
<update id="updatePurgeStatusToOne" parameterType="long">
update snapshots set purge_status = 1 where id = #{id}
</update>
text_value="[null]" tendency="[null]" measure_date="[null]" alert_status="[null]"
description="[null]"/>
- <!-- delete measure on requirement -->
- <!--<project_measures ID="5" project_id="1" SNAPSHOT_ID="1" RULE_ID="[null]" characteristic_id="2" METRIC_ID="1"
- url="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]"
- variation_value_4="[null]"
- variation_value_5="[null]" rule_priority="[null]" alert_text="[null]" VALUE="10.0"
- rules_category_id="[null]"
- person_id="[null]"
- text_value="[null]" tendency="[null]" measure_date="[null]" alert_status="[null]"
- description="[null]"/>-->
-
<!-- delete measure on metrics that are flagged with delete_historical_data=true -->
<!--<project_measures ID="6" project_id="1" SNAPSHOT_ID="1" RULE_ID="[null]" characteristic_id="[null]" METRIC_ID="2"
url="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]"
text_value="[null]" tendency="[null]" measure_date="[null]" alert_status="[null]"
description="[null]"/>
- <!-- delete measure on requirement -->
- <project_measures id="5" project_id="1" snapshot_id="1" rule_id="[null]" characteristic_id="3" metric_id="1"
- url="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]"
- variation_value_4="[null]"
- variation_value_5="[null]" rule_priority="[null]" alert_text="[null]" value="10.0"
- rules_category_id="[null]"
- person_id="[null]"
- text_value="[null]" tendency="[null]" measure_date="[null]" alert_status="[null]"
- description="[null]"/>
-
<!-- delete measure on metrics that are flagged with delete_historical_data=true -->
<project_measures id="6" project_id="1" snapshot_id="1" rule_id="[null]" characteristic_id="[null]" metric_id="2"
url="[null]" variation_value_1="[null]" variation_value_2="[null]" variation_value_3="[null]"