diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/job/CleanHistoryJob.java b/backend/services/system-setting/src/main/java/io/metersphere/system/job/CleanHistoryJob.java index 8b9b3d7cb9..f57adb0550 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/job/CleanHistoryJob.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/job/CleanHistoryJob.java @@ -36,7 +36,7 @@ public class CleanHistoryJob { /** * 清理变更历史 每天凌晨两点执行 */ - @QuartzScheduled(cron = "0 0 2 * * ?") + @QuartzScheduled(cron = "0 34 13 * * ?") public void cleanupLog() { LogUtils.info("clean up history start."); SystemParameter parameter = systemParameterMapper.selectByPrimaryKey(ParamConstants.CleanConfig.OPERATION_HISTORY.getValue()); @@ -56,12 +56,16 @@ public class CleanHistoryJob { } private void doCleanupHistory(int limit) { - //变更历史处理 - List sourceIds = baseOperationHistoryMapper.selectSourceIds(); - int size = 100; - List> batchList = splitList(sourceIds, size); + try { + //变更历史处理 + List sourceIds = baseOperationHistoryMapper.selectSourceIds(); + int size = 100; + List> batchList = splitList(sourceIds, size); + batchList.forEach(batch -> cleanupHistory(batch, limit)); + } catch (Exception e) { + LogUtils.error(e); + } - batchList.forEach(batch -> cleanupHistory(batch, limit)); } private List> splitList(List list, int size) { @@ -75,13 +79,15 @@ public class CleanHistoryJob { public void cleanupHistory(List batch, int limit) { batch.forEach(sourceId -> { List ids = baseOperationHistoryMapper.selectIdsBySourceId(sourceId, limit); - baseOperationHistoryMapper.deleteByIds(sourceId, ids); - List logIds = baseOperationLogMapper.selectIdByHistoryIds(ids); - ids.removeAll(logIds); if (CollectionUtils.isNotEmpty(ids)) { - OperationLogBlobExample blobExample = new OperationLogBlobExample(); - blobExample.createCriteria().andIdIn(ids); - operationLogBlobMapper.deleteByExample(blobExample); + baseOperationHistoryMapper.deleteByIds(sourceId, ids); + List logIds = baseOperationLogMapper.selectIdByHistoryIds(ids); + ids.removeAll(logIds); + if (CollectionUtils.isNotEmpty(ids)) { + OperationLogBlobExample blobExample = new OperationLogBlobExample(); + blobExample.createCriteria().andIdIn(ids); + operationLogBlobMapper.deleteByExample(blobExample); + } } }); }