perf(接口测试): 场景编辑依赖关系优化

This commit is contained in:
fit2-zhao 2024-12-23 18:19:51 +08:00 committed by Craftsman
parent 989c59aaf2
commit d7ada8904f
4 changed files with 50 additions and 37 deletions

View File

@ -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<String> 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<String> contentAnalysis(ApiScenarioWithBLOBs scenarioWithBLOBs) {

View File

@ -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<MultipartFile> bodyFiles, List<MultipartFile> 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;
}

View File

@ -3,19 +3,15 @@
<mapper namespace="io.metersphere.base.mapper.ext.BaseRelationshipEdgeMapper">
<select id="getGraphIdsByNodeIds" resultType="java.lang.String">
select graph_id
select distinct graph_id
from relationship_edge
where source_id in
<foreach collection="ids" item="id" open="(" close=")" separator=",">
#{id}
</foreach>
union
select graph_id
from relationship_edge
where target_id in
or target_id in
<foreach collection="ids" item="id" open="(" close=")" separator=",">
#{id}
</foreach>
</select>
</mapper>

View File

@ -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<RelationshipEdge> relationshipEdges = getEdgesBySaveRequest(request);
LogUtil.info("saveBatch relationshipEdges: " + relationshipEdges.size());
Set<String> 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<String> nextLevelNodes = new ArrayList<>();
ArrayList<String> nextLevelNodes = new ArrayList();
for (RelationshipEdge relationshipEdge : edges) {
if (id.equals(relationshipEdge.getSourceId())) {
nextLevelNodes.add(relationshipEdge.getTargetId());