Skip to content

Commit ab84ee2

Browse files
dbmenesessonartech
authored andcommitted
SONAR-26205 Clean up issue_stats_by_rule_key after project is deleted
1 parent 75bf67f commit ab84ee2

File tree

5 files changed

+43
-0
lines changed

5 files changed

+43
-0
lines changed

server/sonar-db-dao/src/it/java/org/sonar/db/purge/PurgeDaoIT.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,6 +2071,35 @@ void deleteBranch_purgesScaActivity() {
20712071
assertThat(db.countRowsOfTable(dbSession, "sca_analyses")).isEqualTo(1);
20722072
}
20732073

2074+
@Test
2075+
void deleteBranch_purgeIssueStatsByRuleKey() {
2076+
ProjectDto project = db.components().insertPublicProject().getProjectDto();
2077+
BranchDto branch1 = db.components().insertProjectBranch(project);
2078+
BranchDto branch2 = db.components().insertProjectBranch(project);
2079+
2080+
db.executeInsert("issue_stats_by_rule_key",
2081+
"aggregation_type", "PROJECT",
2082+
"aggregation_id", branch1.getUuid(),
2083+
"rule_key", "rule1",
2084+
"issue_count", 1,
2085+
"rating", 2,
2086+
"hotspot_count", 3,
2087+
"hotspots_reviewed", 4);
2088+
2089+
db.executeInsert("issue_stats_by_rule_key",
2090+
"aggregation_type", "PROJECT",
2091+
"aggregation_id", branch2.getUuid(),
2092+
"rule_key", "rule1",
2093+
"issue_count", 1,
2094+
"rating", 2,
2095+
"hotspot_count", 3,
2096+
"hotspots_reviewed", 4);
2097+
2098+
assertThat(db.countRowsOfTable(dbSession, "issue_stats_by_rule_key")).isEqualTo(2);
2099+
underTest.deleteBranch(dbSession, branch1.getUuid());
2100+
assertThat(db.countRowsOfTable(dbSession, "issue_stats_by_rule_key")).isEqualTo(1);
2101+
}
2102+
20742103
@Test
20752104
void deleteProject_purgesScaLicenseProfiles() {
20762105
ProjectDto project = db.components().insertPublicProject().getProjectDto();

server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeCommands.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,13 @@ public void deleteArchitectureGraphs(String branchUuid) {
524524
profiler.stop();
525525
}
526526

527+
public void deleteIssueStatsByRuleKey(String branchUuid) {
528+
profiler.start("deleteIssueStatsByRuleKey (issue_stats_by_rule_key)");
529+
purgeMapper.deleteIssueStatsByRuleKey(branchUuid);
530+
session.commit();
531+
profiler.stop();
532+
}
533+
527534
public void deleteAnticipatedTransitions(String projectUuid, long createdAt) {
528535
profiler.start("deleteAnticipatedTransitions (anticipated_transitions)");
529536
purgeMapper.deleteAnticipatedTransitionsByProjectUuidAndCreationDate(projectUuid, createdAt);

server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeDao.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ private static void deleteBranch(String branchUuid, PurgeCommands commands) {
283283
commands.deleteIssuesFixed(branchUuid);
284284
commands.deleteScaActivity(branchUuid);
285285
commands.deleteArchitectureGraphs(branchUuid);
286+
commands.deleteIssueStatsByRuleKey(branchUuid);
286287
}
287288

288289
private static void deleteProject(String projectUuid, PurgeMapper mapper, PurgeCommands commands) {

server/sonar-db-dao/src/main/java/org/sonar/db/purge/PurgeMapper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,7 @@ void deleteCeActivityByRootUuidOrBefore(@Nullable @Param("rootUuid") String root
208208
void deleteScaLicenseProfileProjectsByProjectUuid(@Param("projectUuid") String projectUuid);
209209

210210
void deleteArchitectureGraphsByBranchUuid(@Param("branchUuid") String branchUuid);
211+
212+
void deleteIssueStatsByRuleKey(@Param("branchUuid") String branchUuid);
213+
211214
}

server/sonar-db-dao/src/main/resources/org/sonar/db/purge/PurgeMapper.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,4 +694,7 @@
694694
<delete id="deleteScaLicenseProfileProjectsByProjectUuid">
695695
delete from sca_lic_prof_projects where project_uuid = #{projectUuid,jdbcType=VARCHAR}
696696
</delete>
697+
<delete id="deleteIssueStatsByRuleKey">
698+
delete from issue_stats_by_rule_key where aggregation_type = 'PROJECT' and aggregation_id = #{branchUuid,jdbcType=VARCHAR}
699+
</delete>
697700
</mapper>

0 commit comments

Comments
 (0)