From d7ada8904f42fed2be1ceb65f052fbdd13a8048f Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Mon, 23 Dec 2024 18:19:51 +0800 Subject: [PATCH] =?UTF-8?q?perf(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E5=9C=BA=E6=99=AF=E7=BC=96=E8=BE=91=E4=BE=9D=E8=B5=96=E5=85=B3?= =?UTF-8?q?=E7=B3=BB=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ApiAutomationRelationshipEdgeService.java | 19 ++++---- .../service/scenario/ApiScenarioService.java | 46 +++++++++++++------ .../mapper/ext/BaseRelationshipEdgeMapper.xml | 8 +--- .../service/RelationshipEdgeService.java | 14 +++--- 4 files changed, 50 insertions(+), 37 deletions(-) diff --git a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiAutomationRelationshipEdgeService.java b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiAutomationRelationshipEdgeService.java index 84c3e5e401..128dce7088 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiAutomationRelationshipEdgeService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiAutomationRelationshipEdgeService.java @@ -40,6 +40,15 @@ public class ApiAutomationRelationshipEdgeService { beforeReferenceRelationships = this.contentAnalysis(preBlobs); } + // 如果有新增的关系,进行批量保存 + if (CollectionUtils.isNotEmpty(referenceRelationships)) { + RelationshipEdgeRequest request = new RelationshipEdgeRequest(); + request.setId(scenarioWithBLOBs.getId()); + request.setTargetIds(referenceRelationships); + request.setType("API_SCENARIO"); + relationshipEdgeService.saveBatch(request); + } + // 比较并处理关系 List removedRelationships = new ArrayList<>(beforeReferenceRelationships); removedRelationships.removeAll(referenceRelationships); @@ -48,16 +57,6 @@ public class ApiAutomationRelationshipEdgeService { if (CollectionUtils.isNotEmpty(removedRelationships)) { new Thread(() -> relationshipEdgeService.delete(scenarioWithBLOBs.getId(), removedRelationships)).start(); } - - // 如果有新增的关系,进行批量保存 - if (CollectionUtils.isNotEmpty(referenceRelationships)) { - RelationshipEdgeRequest request = new RelationshipEdgeRequest(); - request.setId(scenarioWithBLOBs.getId()); - request.setTargetIds(referenceRelationships); - request.setType("API_SCENARIO"); - - relationshipEdgeService.saveBatch(request); - } } private List contentAnalysis(ApiScenarioWithBLOBs scenarioWithBLOBs) { diff --git a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioService.java b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioService.java index f1a4fa2e36..d30563595d 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioService.java @@ -300,10 +300,19 @@ public class ApiScenarioService { scenario.setRefId(request.getId()); scenario.setLatest(true); - apiScenarioMapper.insert(scenario); - apiScenarioReferenceIdService.saveApiAndScenarioRelation(scenario); // 存储依赖关系 + LogUtil.info("initRelationshipEdge start"); apiAutomationRelationshipEdgeService.initRelationshipEdge(null, scenario); + LogUtil.info("initRelationshipEdge end"); + + apiScenarioMapper.insert(scenario); + + // 依赖关系处理 + new Thread(() -> { + apiScenarioReferenceIdService.saveApiAndScenarioRelation(scenario); + uploadFiles(request, bodyFiles, scenarioFiles); + }).start(); + apiTestCaseService.checkAndSendReviewMessage( scenario.getId(), scenario.getName(), @@ -315,7 +324,6 @@ public class ApiScenarioService { scenario.getPrincipal() ); - uploadFiles(request, bodyFiles, scenarioFiles); return scenario; } @@ -373,6 +381,7 @@ public class ApiScenarioService { } public ApiScenarioWithBLOBs update(SaveApiScenarioRequest request, List bodyFiles, List scenarioFiles) { + LogUtil.info("update scenario start"); checkNameExist(request, false); checkScenarioNum(request); //如果场景有TCP步骤的话,也要做参数计算处理 @@ -412,12 +421,26 @@ public class ApiScenarioService { apiScenarioMapper.updateByExampleSelective(apiScenarioWithBLOBs, example); } - apiScenarioReferenceIdService.saveApiAndScenarioRelation(scenario); - extScheduleMapper.updateNameByResourceID(request.getId(), request.getName());// 修改场景name,同步到修改首页定时任务 - uploadFiles(request, bodyFiles, scenarioFiles); - // 存储依赖关系 + LogUtil.info("initRelationshipEdge start"); apiAutomationRelationshipEdgeService.initRelationshipEdge(beforeScenario, scenario); + LogUtil.info("initRelationshipEdge end"); + + new Thread(() -> { + apiScenarioReferenceIdService.saveApiAndScenarioRelation(scenario); + extScheduleMapper.updateNameByResourceID(request.getId(), request.getName());// 修改场景name,同步到修改首页定时任务 + uploadFiles(request, bodyFiles, scenarioFiles); + + String defaultVersion = baseProjectVersionMapper.getDefaultVersion(request.getProjectId()); + if (StringUtils.equalsIgnoreCase(request.getVersionId(), defaultVersion)) { + checkAndSetLatestVersion(beforeScenario.getRefId()); + } + //同步修改所有版本的模块路径 + updateOtherVersionModule(beforeScenario.getRefId(), scenario); + // 存储附件关系 + extFileAssociationService.saveScenario(scenario.getId(), request.getScenarioDefinition()); + + }).start(); apiTestCaseService.checkAndSendReviewMessage( scenario.getId(), @@ -430,14 +453,7 @@ public class ApiScenarioService { scenario.getPrincipal() ); - String defaultVersion = baseProjectVersionMapper.getDefaultVersion(request.getProjectId()); - if (StringUtils.equalsIgnoreCase(request.getVersionId(), defaultVersion)) { - checkAndSetLatestVersion(beforeScenario.getRefId()); - } - //同步修改所有版本的模块路径 - updateOtherVersionModule(beforeScenario.getRefId(), scenario); - // 存储附件关系 - extFileAssociationService.saveScenario(scenario.getId(), request.getScenarioDefinition()); + LogUtil.info("update scenario end"); return scenario; } diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/base/mapper/ext/BaseRelationshipEdgeMapper.xml b/framework/sdk-parent/sdk/src/main/java/io/metersphere/base/mapper/ext/BaseRelationshipEdgeMapper.xml index e616291808..f073f1c778 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/base/mapper/ext/BaseRelationshipEdgeMapper.xml +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/base/mapper/ext/BaseRelationshipEdgeMapper.xml @@ -3,19 +3,15 @@ - diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/RelationshipEdgeService.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/RelationshipEdgeService.java index f558b17820..3c5aa8db70 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/RelationshipEdgeService.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/RelationshipEdgeService.java @@ -7,6 +7,7 @@ import io.metersphere.base.domain.RelationshipEdgeKey; import io.metersphere.base.mapper.RelationshipEdgeMapper; import io.metersphere.base.mapper.ext.BaseRelationshipEdgeMapper; import io.metersphere.commons.exception.MSException; +import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.SessionUtils; import io.metersphere.request.RelationshipEdgeRequest; import org.apache.commons.collections.CollectionUtils; @@ -206,7 +207,10 @@ public class RelationshipEdgeService { */ public void saveBatch(RelationshipEdgeRequest request) { String graphId = UUID.randomUUID().toString(); + LogUtil.info("saveBatch graphId: " + graphId); List relationshipEdges = getEdgesBySaveRequest(request); + + LogUtil.info("saveBatch relationshipEdges: " + relationshipEdges.size()); Set addEdgesIds = new HashSet<>(); if (CollectionUtils.isNotEmpty(request.getTargetIds())) { @@ -235,7 +239,8 @@ public class RelationshipEdgeService { MSException.throwException("关联后存在循环依赖,请检查依赖关系"); } }); - // 合并图 + + LogUtil.info("开始合并图内容"); new Thread(() -> { SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); RelationshipEdgeMapper batchMapper = sqlSession.getMapper(RelationshipEdgeMapper.class); @@ -258,7 +263,6 @@ public class RelationshipEdgeService { if (sqlSessionFactory != null) { SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); } - }).start(); } @@ -293,11 +297,9 @@ public class RelationshipEdgeService { if (CollectionUtils.isEmpty(graphIds)) { return new ArrayList<>(); } - RelationshipEdgeExample example = new RelationshipEdgeExample(); example.createCriteria() - .andGraphIdIn(graphIds.stream() - .distinct().collect(Collectors.toList())); + .andGraphIdIn(graphIds); return relationshipEdgeMapper.selectByExample(example); } @@ -321,7 +323,7 @@ public class RelationshipEdgeService { markSet.add(id); visitedSet.add(id); - ArrayList nextLevelNodes = new ArrayList<>(); + ArrayList nextLevelNodes = new ArrayList(); for (RelationshipEdge relationshipEdge : edges) { if (id.equals(relationshipEdge.getSourceId())) { nextLevelNodes.add(relationshipEdge.getTargetId());