.containsOnly(project.uuid(), otherView.uuid(), otherSubView.uuid(), otherProjectCopy.uuid());
}
+ @Test
+ public void purge_shouldDeleteOrphanIssues() {
+ RuleDto rule = db.rules().insert();
+ ComponentDto project = db.components().insertPublicProject();
+ ComponentDto otherProject = db.components().insertPublicProject();
+ ComponentDto dir = db.components().insertComponent(newDirectory(project, "path"));
+ ComponentDto file = db.components().insertComponent(newFileDto(project, dir));
+
+ IssueDto issue1 = db.issues().insert(rule, project, file);
+ IssueDto orphanIssue = db.issues().insert(rule, project, file, issue -> issue.setComponentUuid("nonExisting"));
+ IssueChangeDto orphanIssueChange = db.issues().insertChange(orphanIssue);
+ db.issues().insertNewCodeReferenceIssue(orphanIssue);
+
+ underTest.purge(dbSession, newConfigurationWith30Days(system2, project.uuid(), project.uuid()), PurgeListener.EMPTY, new PurgeProfiler());
+ db.commit();
+
+ assertThat(db.countRowsOfTable("issue_changes")).isZero();
+ assertThat(db.countRowsOfTable("new_code_reference_issues")).isZero();
+ assertThat(db.select("select kee as \"KEE\" from issues")).extracting(i -> i.get("KEE")).containsOnly(issue1.getKey());
+ }
+
@Test
public void should_delete_old_closed_issues() {
RuleDto rule = db.rules().insert();
purgeAnalyses(commands, rootUuid);
purgeDisabledComponents(commands, conf, listener);
deleteOldClosedIssues(conf, mapper, listener);
+ deleteOrphanIssues(mapper, rootUuid);
purgeOldCeActivities(rootUuid, commands);
purgeOldCeScannerContexts(rootUuid, commands);
commands.purgeDisabledComponents(rootUuid, conf.getDisabledComponentUuids(), listener);
}
+ private static void deleteOrphanIssues(PurgeMapper mapper, String rootUuid) {
+ LOG.debug("<- Delete orphan issues");
+ List<String> issueKeys = mapper.selectBranchOrphanIssues(rootUuid);
+ deleteIssues(mapper, issueKeys);
+ }
+
private static void deleteOldClosedIssues(PurgeConfiguration conf, PurgeMapper mapper, PurgeListener listener) {
Date toDate = conf.maxLiveDateOfClosedIssues();
String rootUuid = conf.rootUuid();
List<String> issueKeys = mapper.selectOldClosedIssueKeys(rootUuid, dateToLong(toDate));
+ deleteIssues(mapper, issueKeys);
+ listener.onIssuesRemoval(rootUuid, issueKeys);
+ }
+
+ private static void deleteIssues(PurgeMapper mapper, Collection<String> issueKeys) {
executeLargeInputs(issueKeys, input -> {
mapper.deleteIssueChangesFromIssueKeys(input);
return emptyList();
mapper.deleteIssuesFromKeys(input);
return emptyList();
});
- listener.onIssuesRemoval(rootUuid, issueKeys);
}
private static void deleteAbortedAnalyses(String rootUuid, PurgeCommands commands) {