From 9e3799b5f23d9d4b6ce65cc1a0e250aaf64dc26a Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Fri, 12 Apr 2024 14:31:48 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=B3=BB=E7=BB=9F):=20=E8=B5=84?= =?UTF-8?q?=E6=BA=90id=E4=B8=8D=E5=AD=98=E5=9C=A8=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E6=95=B4=E4=B8=AA=E4=BB=BB=E5=8A=A1=E5=81=9C?= =?UTF-8?q?=E6=AD=A2=E4=BA=86=E7=9A=84=E6=BD=9C=E5=9C=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/job/CleanHistoryJob.java | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) 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); + } } }); }