}
LOG.debug("<- Purge stale branches");
- List<String> branchUuids = mapper.selectStaleShortLivingBranchesAndPullRequests(rootUuid, dateToLong(maxDate.get()));
+ List<String> branchUuids = mapper.selectStaleShortLivingBranches(rootUuid, dateToLong(maxDate.get()));
for (String branchUuid : branchUuids) {
deleteRootComponent(branchUuid, mapper, commands);
List<String> selectOldClosedIssueKeys(@Param("projectUuid") String projectUuid, @Nullable @Param("toDate") Long toDate);
- List<String> selectStaleShortLivingBranchesAndPullRequests(@Param("mainBranchProjectUuid") String mainBranchProjectUuid, @Param("toDate") Long toDate);
+ List<String> selectStaleShortLivingBranches(@Param("mainBranchProjectUuid") String mainBranchProjectUuid, @Param("toDate") Long toDate);
void deleteIssuesFromKeys(@Param("keys") List<String> keys);
and not exists(select e.id from events e where e.analysis_uuid=s.uuid)
</select>
- <select id="selectStaleShortLivingBranchesAndPullRequests" parameterType="map" resultType="String">
+ <select id="selectStaleShortLivingBranches" parameterType="map" resultType="String">
select
pb.uuid
from
project_branches pb
where
pb.project_uuid=#{mainBranchProjectUuid,jdbcType=VARCHAR}
- and (pb.branch_type='SHORT' or pb.branch_type='PULL_REQUEST')
+ and pb.branch_type='SHORT'
and pb.updated_at < #{toDate}
</select>
assertThat(getUuidsInTableProjects()).containsOnly(project.uuid(), longBranch.uuid(), recentShortBranch.uuid());
}
- @Test
- public void purge_inactive_pull_request() {
- when(system2.now()).thenReturn(new Date().getTime());
- RuleDefinitionDto rule = dbTester.rules().insert();
- ComponentDto project = dbTester.components().insertMainBranch();
- ComponentDto longBranch = dbTester.components().insertProjectBranch(project);
- ComponentDto recentPullRequest = dbTester.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.PULL_REQUEST));
-
- // pull request with other components and issues, updated 31 days ago
- when(system2.now()).thenReturn(DateUtils.addDays(new Date(), -31).getTime());
- ComponentDto pullRequest = dbTester.components().insertProjectBranch(project, b -> b.setBranchType(BranchType.PULL_REQUEST));
- ComponentDto module = dbTester.components().insertComponent(newModuleDto(pullRequest));
- ComponentDto subModule = dbTester.components().insertComponent(newModuleDto(module));
- ComponentDto file = dbTester.components().insertComponent(newFileDto(subModule));
- dbTester.issues().insert(rule, pullRequest, file);
- dbTester.issues().insert(rule, pullRequest, subModule);
- dbTester.issues().insert(rule, pullRequest, module);
-
- // back to present
- when(system2.now()).thenReturn(new Date().getTime());
- underTest.purge(dbSession, newConfigurationWith30Days(system2, project.uuid()), PurgeListener.EMPTY, new PurgeProfiler());
- dbSession.commit();
-
- assertThat(getUuidsInTableProjects()).containsOnly(project.uuid(), longBranch.uuid(), recentPullRequest.uuid());
- }
-
@Test
public void shouldDeleteHistoricalDataOfDirectoriesAndFiles() {
dbTester.prepareDbUnit(getClass(), "shouldDeleteHistoricalDataOfDirectoriesAndFiles.xml");