diff options
author | Simon Brandhof <simon.brandhof@gmail.com> | 2012-03-05 14:05:37 +0100 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@gmail.com> | 2012-03-05 14:05:37 +0100 |
commit | 15efef19303c240d12ec345e774987ba8a075d8d (patch) | |
tree | a644815b44576bcf59fdd9c22dd581c4c6981b71 /plugins | |
parent | 449823bb51378c333f4028d1ff015d5c50e973d9 (diff) | |
download | sonarqube-15efef19303c240d12ec345e774987ba8a075d8d.tar.gz sonarqube-15efef19303c240d12ec345e774987ba8a075d8d.zip |
Improve purge tasks of DbCleaner
* improve logs
* decrease the nb of SQL requests required to purge aborted builds and historical data of directories/files
Diffstat (limited to 'plugins')
3 files changed, 9 insertions, 10 deletions
diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DefaultPurgeTask.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DefaultPurgeTask.java index c5e963aefcc..cdb55dd86ad 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DefaultPurgeTask.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/DefaultPurgeTask.java @@ -40,7 +40,7 @@ import org.sonar.plugins.dbcleaner.period.DefaultPeriodCleaner; name = "Clean history data of directories/packages") }) public class DefaultPurgeTask implements PurgeTask { - private static final Logger LOG = LoggerFactory.getLogger(ProjectPurgePostJob.class); + private static final Logger LOG = LoggerFactory.getLogger(DefaultPurgeTask.class); private PurgeDao purgeDao; private Settings settings; @@ -58,6 +58,7 @@ public class DefaultPurgeTask implements PurgeTask { } public PurgeTask purge(long resourceId) { + LOG.info("Clean historical data [id=" + resourceId + "]"); cleanHistoricalData(resourceId); doPurge(resourceId); return this; @@ -65,8 +66,7 @@ public class DefaultPurgeTask implements PurgeTask { private void cleanHistoricalData(long resourceId) { try { - LOG.debug("Clean historical data [id=" + resourceId + "]"); - periodCleaner.purge(resourceId); + periodCleaner.clean(resourceId); } catch (Exception e) { // purge errors must no fail the batch LOG.error("Fail to clean historical data [id=" + resourceId + "]", e); @@ -82,7 +82,6 @@ public class DefaultPurgeTask implements PurgeTask { private void doPurge(long resourceId) { try { - LOG.debug("Purge data [id=" + resourceId + "]"); purgeDao.purge(resourceId, getScopesWithoutHistoricalData()); } catch (Exception e) { // purge errors must no fail the batch diff --git a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/DefaultPeriodCleaner.java b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/DefaultPeriodCleaner.java index efc9ff49d64..9b9bc9e1dc6 100644 --- a/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/DefaultPeriodCleaner.java +++ b/plugins/sonar-dbcleaner-plugin/src/main/java/org/sonar/plugins/dbcleaner/period/DefaultPeriodCleaner.java @@ -44,15 +44,15 @@ public class DefaultPeriodCleaner implements PeriodCleaner { } public void purge(Project project, int projectSnapshotId) { - purge((long) project.getId()); + clean((long) project.getId()); } - public void purge(long projectId) { - doPurge(projectId, new Filters(settings).getFilters()); + public void clean(long projectId) { + doClean(projectId, new Filters(settings).getFilters()); } @VisibleForTesting - void doPurge(long projectId, List<Filter> filters) { + void doClean(long projectId, List<Filter> filters) { List<PurgeableSnapshotDto> history = selectProjectSnapshots(projectId); for (Filter filter : filters) { filter.log(); diff --git a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/DefaultPeriodCleanerTest.java b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/DefaultPeriodCleanerTest.java index ca806d648fc..0d4ba72ebd9 100644 --- a/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/DefaultPeriodCleanerTest.java +++ b/plugins/sonar-dbcleaner-plugin/src/test/java/org/sonar/plugins/dbcleaner/period/DefaultPeriodCleanerTest.java @@ -39,7 +39,7 @@ public class DefaultPeriodCleanerTest { @Test - public void doPurge() { + public void doClean() { PurgeDao dao = mock(PurgeDao.class); when(dao.selectPurgeableSnapshots(123L)).thenReturn(Arrays.asList( new PurgeableSnapshotDto().setSnapshotId(999L).setDate(new Date()))); @@ -47,7 +47,7 @@ public class DefaultPeriodCleanerTest { Filter filter2 = newLazyFilter(); DefaultPeriodCleaner cleaner = new DefaultPeriodCleaner(dao, mock(Settings.class)); - cleaner.doPurge(123L, Arrays.asList(filter1, filter2)); + cleaner.doClean(123L, Arrays.asList(filter1, filter2)); verify(filter1).log(); verify(filter2).log(); |