From 841a85a4c9516297e0ec340367bd36f3e1f5990b Mon Sep 17 00:00:00 2001 From: CaptainB Date: Wed, 3 Apr 2024 13:02:35 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E4=BD=BF=E7=94=A8=E4=B8=80=E4=B8=AA=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/job/CleanHistoryJob.java | 9 +- .../system/job/CleanUpReportJob.java | 100 +++++++++--------- 2 files changed, 49 insertions(+), 60 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 4b676867ca..3108ea3422 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 @@ -57,14 +57,7 @@ public class CleanHistoryJob { int size = 100; List> batchList = splitList(sourceIds, size); - batchList.forEach(batch -> { - Thread.startVirtualThread(new Runnable() { - @Override - public void run() { - cleanupHistory(batch, limit); - } - }); - }); + batchList.forEach(batch -> cleanupHistory(batch, limit)); } private List> splitList(List list, int size) { diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/job/CleanUpReportJob.java b/backend/services/system-setting/src/main/java/io/metersphere/system/job/CleanUpReportJob.java index 1a86e158d1..3f244c3bf9 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/job/CleanUpReportJob.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/job/CleanUpReportJob.java @@ -49,60 +49,56 @@ public class CleanUpReportJob { for (int i = 0; i < pages; i++) { int start = i * 100; - Thread.startVirtualThread(new Runnable() { - @Override - public void run() { - List projects = baseProjectMapper.selectProjectByLimit(start,100); - projects.forEach(project -> { - ProjectApplicationExample applicationExample = new ProjectApplicationExample(); - //test_plan - applicationExample.createCriteria().andProjectIdEqualTo(project.getId()).andTypeEqualTo(ProjectApplicationType.TEST_PLAN.TEST_PLAN_CLEAN_REPORT.name()); - List testPlan = projectApplicationMapper.selectByExample(applicationExample); - Map map = new HashMap<>(); - if (CollectionUtils.isNotEmpty(testPlan)) { - map.put(ProjectApplicationType.TEST_PLAN.TEST_PLAN_CLEAN_REPORT.name(), testPlan.get(0).getTypeValue()); - } else { - map.put(ProjectApplicationType.TEST_PLAN.TEST_PLAN_CLEAN_REPORT.name(), "3M"); - } - - //ui - applicationExample.clear(); - applicationExample.createCriteria().andProjectIdEqualTo(project.getId()).andTypeEqualTo(ProjectApplicationType.UI.UI_CLEAN_REPORT.name()); - List ui = projectApplicationMapper.selectByExample(applicationExample); - if (CollectionUtils.isNotEmpty(ui)) { - map.put(ProjectApplicationType.UI.UI_CLEAN_REPORT.name(), ui.get(0).getTypeValue()); - } else { - map.put(ProjectApplicationType.UI.UI_CLEAN_REPORT.name(), "3M"); - } - - //load_test - applicationExample.clear(); - applicationExample.createCriteria().andProjectIdEqualTo(project.getId()).andTypeEqualTo(ProjectApplicationType.LOAD_TEST.LOAD_TEST_CLEAN_REPORT.name()); - List loadTest = projectApplicationMapper.selectByExample(applicationExample); - if (CollectionUtils.isNotEmpty(loadTest)) { - map.put(ProjectApplicationType.LOAD_TEST.LOAD_TEST_CLEAN_REPORT.name(), loadTest.get(0).getTypeValue()); - } else { - map.put(ProjectApplicationType.LOAD_TEST.LOAD_TEST_CLEAN_REPORT.name(), "3M"); - } - - //api - applicationExample.clear(); - applicationExample.createCriteria().andProjectIdEqualTo(project.getId()).andTypeEqualTo(ProjectApplicationType.API.API_CLEAN_REPORT.name()); - List api = projectApplicationMapper.selectByExample(applicationExample); - if (CollectionUtils.isNotEmpty(api)) { - map.put(ProjectApplicationType.API.API_CLEAN_REPORT.name(), api.get(0).getTypeValue()); - } else { - map.put(ProjectApplicationType.API.API_CLEAN_REPORT.name(), "3M"); - } - - Map beansOfType = applicationContext.getBeansOfType(BaseCleanUpReport.class); - beansOfType.forEach((k, v) -> { - v.cleanReport(map, project.getId()); - }); - - }); + List projects = baseProjectMapper.selectProjectByLimit(start, 100); + projects.forEach(project -> { + ProjectApplicationExample applicationExample = new ProjectApplicationExample(); + //test_plan + applicationExample.createCriteria().andProjectIdEqualTo(project.getId()).andTypeEqualTo(ProjectApplicationType.TEST_PLAN.TEST_PLAN_CLEAN_REPORT.name()); + List testPlan = projectApplicationMapper.selectByExample(applicationExample); + Map map = new HashMap<>(); + if (CollectionUtils.isNotEmpty(testPlan)) { + map.put(ProjectApplicationType.TEST_PLAN.TEST_PLAN_CLEAN_REPORT.name(), testPlan.get(0).getTypeValue()); + } else { + map.put(ProjectApplicationType.TEST_PLAN.TEST_PLAN_CLEAN_REPORT.name(), "3M"); } + + //ui + applicationExample.clear(); + applicationExample.createCriteria().andProjectIdEqualTo(project.getId()).andTypeEqualTo(ProjectApplicationType.UI.UI_CLEAN_REPORT.name()); + List ui = projectApplicationMapper.selectByExample(applicationExample); + if (CollectionUtils.isNotEmpty(ui)) { + map.put(ProjectApplicationType.UI.UI_CLEAN_REPORT.name(), ui.get(0).getTypeValue()); + } else { + map.put(ProjectApplicationType.UI.UI_CLEAN_REPORT.name(), "3M"); + } + + //load_test + applicationExample.clear(); + applicationExample.createCriteria().andProjectIdEqualTo(project.getId()).andTypeEqualTo(ProjectApplicationType.LOAD_TEST.LOAD_TEST_CLEAN_REPORT.name()); + List loadTest = projectApplicationMapper.selectByExample(applicationExample); + if (CollectionUtils.isNotEmpty(loadTest)) { + map.put(ProjectApplicationType.LOAD_TEST.LOAD_TEST_CLEAN_REPORT.name(), loadTest.get(0).getTypeValue()); + } else { + map.put(ProjectApplicationType.LOAD_TEST.LOAD_TEST_CLEAN_REPORT.name(), "3M"); + } + + //api + applicationExample.clear(); + applicationExample.createCriteria().andProjectIdEqualTo(project.getId()).andTypeEqualTo(ProjectApplicationType.API.API_CLEAN_REPORT.name()); + List api = projectApplicationMapper.selectByExample(applicationExample); + if (CollectionUtils.isNotEmpty(api)) { + map.put(ProjectApplicationType.API.API_CLEAN_REPORT.name(), api.get(0).getTypeValue()); + } else { + map.put(ProjectApplicationType.API.API_CLEAN_REPORT.name(), "3M"); + } + + Map beansOfType = applicationContext.getBeansOfType(BaseCleanUpReport.class); + beansOfType.forEach((k, v) -> { + v.cleanReport(map, project.getId()); + }); + }); + } }