refactor(接口测试): 优化场景更新方法

【【接口测试】github#31887,在接口自动化场景的当中,跨工作空间引用场景。点击保存,F12查看接口请求特别长。】
https://www.tapd.cn/55049933/bugtrace/bugs/view?bug_id=1155049933001043717

Signed-off-by: fit2-zhao <yong.zhao@fit2cloud.com>
This commit is contained in:
fit2-zhao 2024-07-12 15:38:45 +08:00 committed by Craftsman
parent 1c6fa21898
commit 028b641e02
3 changed files with 29 additions and 26 deletions

View File

@ -40,8 +40,7 @@ public class ExtFileAssociationService extends FileAssociationService {
public void saveScenario(String id, MsTestElement scenario) { public void saveScenario(String id, MsTestElement scenario) {
this.deleteByResourceId(id); this.deleteByResourceId(id);
List<BodyFile> files = new ArrayList<>(); List<BodyFile> files = new ArrayList<>();
if (scenario != null && scenario instanceof MsScenario) { if (scenario instanceof MsScenario msScenario) {
MsScenario msScenario = (MsScenario) scenario;
if (!CollectionUtils.isEmpty(msScenario.getVariables())) { if (!CollectionUtils.isEmpty(msScenario.getVariables())) {
msScenario.getVariables().stream().filter(ScenarioVariable::isCSVValid).forEach(keyValue -> { msScenario.getVariables().stream().filter(ScenarioVariable::isCSVValid).forEach(keyValue -> {
files.addAll(keyValue.getFiles().stream().filter(BodyFile::isRef).collect(Collectors.toList())); files.addAll(keyValue.getFiles().stream().filter(BodyFile::isRef).collect(Collectors.toList()));

View File

@ -386,8 +386,8 @@ public class ApiScenarioService {
} else { } else {
scenario.setVersion(version + 1); scenario.setVersion(version + 1);
} }
new Thread(() -> deleteUpdateBodyFile(scenario, beforeScenario)).start();
deleteUpdateBodyFile(scenario, beforeScenario);
scenario.setCreateUser(null); // 更新时不更新创建人 scenario.setCreateUser(null); // 更新时不更新创建人
ApiScenarioExample example = new ApiScenarioExample(); ApiScenarioExample example = new ApiScenarioExample();
example.createCriteria().andIdEqualTo(scenario.getId()).andVersionIdEqualTo(request.getVersionId()); example.createCriteria().andIdEqualTo(scenario.getId()).andVersionIdEqualTo(request.getVersionId());
@ -412,32 +412,36 @@ public class ApiScenarioService {
apiScenarioMapper.updateByExampleSelective(apiScenarioWithBLOBs, example); apiScenarioMapper.updateByExampleSelective(apiScenarioWithBLOBs, example);
} }
apiScenarioReferenceIdService.saveApiAndScenarioRelation(scenario);
extScheduleMapper.updateNameByResourceID(request.getId(), request.getName());// 修改场景name同步到修改首页定时任务 extScheduleMapper.updateNameByResourceID(request.getId(), request.getName());// 修改场景name同步到修改首页定时任务
uploadFiles(request, bodyFiles, scenarioFiles);
// 存储依赖关系 // 异步数据放到线程中处理
apiAutomationRelationshipEdgeService.initRelationshipEdge(beforeScenario, scenario); new Thread(() -> {
uploadFiles(request, bodyFiles, scenarioFiles);
apiScenarioReferenceIdService.saveApiAndScenarioRelation(scenario);
// 存储依赖关系
apiAutomationRelationshipEdgeService.initRelationshipEdge(beforeScenario, scenario);
apiTestCaseService.checkAndSendReviewMessage( apiTestCaseService.checkAndSendReviewMessage(
scenario.getId(), scenario.getId(),
scenario.getName(), scenario.getName(),
scenario.getProjectId(), scenario.getProjectId(),
"场景用例通知", "场景用例通知",
NoticeConstants.TaskType.API_AUTOMATION_TASK, NoticeConstants.TaskType.API_AUTOMATION_TASK,
beforeScenario.getScenarioDefinition(), beforeScenario.getScenarioDefinition(),
scenario.getScenarioDefinition(), scenario.getScenarioDefinition(),
scenario.getPrincipal() 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());
}).start();
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());
return scenario; return scenario;
} }

View File

@ -122,7 +122,7 @@ public class FileAssociationService {
batchMapper.insert(fileAssociation); batchMapper.insert(fileAssociation);
}); });
sqlSession.flushStatements(); sqlSession.flushStatements();
if (sqlSession != null && sqlSessionFactory != null) { if (sqlSessionFactory != null) {
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
} }
} }