refactor(接口测试): 优化场景模块树加载效率

--story=1011189 --user=赵勇 系统左侧模块树加载效率优化 https://www.tapd.cn/55049933/s/1343693
This commit is contained in:
fit2-zhao 2023-02-28 17:43:50 +08:00 committed by fit2-zhao
parent 78a1e9deb6
commit f17a628381
8 changed files with 26 additions and 184 deletions

View File

@ -3,6 +3,7 @@ package io.metersphere.base.mapper.ext;
import io.metersphere.api.dto.ApiCountChartResult;
import io.metersphere.api.dto.ApiCountRequest;
import io.metersphere.api.dto.automation.ApiScenarioDTO;
import io.metersphere.api.dto.automation.ApiScenarioModuleDTO;
import io.metersphere.api.dto.automation.ApiScenarioRequest;
import io.metersphere.api.dto.datacount.ApiDataCountResult;
import io.metersphere.base.domain.ApiScenario;
@ -14,18 +15,11 @@ import io.metersphere.request.BaseQueryRequest;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
import java.util.Set;
public interface ExtApiScenarioMapper {
List<ApiScenarioDTO> list(@Param("request") ApiScenarioRequest request);
int listModule(@Param("request") ApiScenarioRequest request);
List<ApiScenarioDTO> listReview(@Param("request") ApiScenarioRequest request);
List<ApiScenarioWithBLOBs> selectByTagId(@Param("id") String id);
List<ApiScenarioDTO> selectIds(@Param("ids") List<String> ids);
int selectTrash(@Param("projectId") String projectId);
@ -44,36 +38,18 @@ public interface ExtApiScenarioMapper {
List<ApiDataCountResult> countRunResultByProjectID(@Param("projectId") String projectId, @Param("versionId") String versionId);
List<String> selectIdsNotExistsInPlan(String projectId, String planId);
ApiScenario getNextNum(@Param("projectId") String projectId);
List<String> selectIdsByQuery(@Param("request") BaseQueryRequest request);
List<String> selectIdsByProjectId(String projectId);
void updateCustomNumByProjectId(@Param("projectId") String projectId);
List<ApiScenarioWithBLOBs> listWithIds(@Param("ids") List<String> ids);
List<ApiScenarioWithBLOBs> listWithRefIds(@Param("ids") List<String> ids);
List<Map<String, Object>> listModuleByCollection(@Param("request") ApiScenarioRequest request);
String selectNameById(String id);
List<String> selectNameByIdIn(@Param("ids") List<String> id);
List<ApiScenarioWithBLOBs> selectByNoReferenceId();
List<ApiScenarioModuleDTO> listModuleByCollection(@Param("request") ApiScenarioRequest request);
void checkOriginalStatusByIds(@Param("ids") List<String> ids);
List<String> selectIdsByExecuteTimeIsNull();
long countExecuteTimesByProjectID(String projectId);
List<String> selectProjectIds();
List<String> getIdsOrderByUpdateTime(@Param("projectId") String projectId);
Long getPreOrder(@Param("projectId") String projectId, @Param("baseOrder") Long baseOrder);
@ -82,8 +58,6 @@ public interface ExtApiScenarioMapper {
List<RelationshipGraphData.Node> getTestCaseForGraph(@Param("ids") Set<String> ids);
void setScenarioEnvGroupIdNull(@Param("environmentGroupId") String environmentGroupId);
ApiScenarioDTO selectById(@Param("id") String id);
void clearLatestVersion(String refId);
@ -92,10 +66,6 @@ public interface ExtApiScenarioMapper {
void updateVersionModule(@Param("refId") String refId, @Param("versionId") String versionId, @Param("moduleId") String moduleId, @Param("modulePath") String modulePath);
List<String> selectRefIdsForVersionChange(@Param("versionId") String versionId, @Param("projectId") String projectId);
List<ApiScenarioWithBLOBs> selectByStatusIsNotTrash();
List<ApiScenarioWithBLOBs> selectRepeatByBLOBs(@Param("names") List<String> names, @Param("projectId") String projectId);
List<String> selectRelevanceIdsByQuery(@Param("request") BaseQueryRequest query);

View File

@ -175,16 +175,17 @@
</include>
</if>
</sql>
<select id="listModule" resultType="java.lang.Integer">
select count(api_scenario.id) from api_scenario
left join project on api_scenario.project_id = project.id
<include refid="queryWhereCondition"/>
</select>
<select id="listModuleByCollection" resultType="java.util.Map">
select api_scenario_module_id AS moduleId,count(id) AS countNum from api_scenario
<include refid="queryWhereCondition"/>
GROUP BY api_scenario_module_id
<select id="listModuleByCollection" resultType="io.metersphere.api.dto.automation.ApiScenarioModuleDTO">
SELECT
m.id,
count(*) AS caseNum
FROM
api_scenario
LEFT JOIN api_scenario_module m ON api_scenario.api_scenario_module_id = m.id
<include refid="queryWhereCondition"/>
GROUP BY
m.id
</select>
<select id="list" resultMap="BaseResultMap">
select api_scenario.id, api_scenario.project_id, api_scenario.tags, api_scenario.user_id, api_scenario.num,
@ -421,12 +422,6 @@
</if>
</sql>
<select id="selectByTagId" resultType="io.metersphere.base.domain.ApiScenarioWithBLOBs">
select *
from api_scenario
where tags like CONCAT('%', #{id}, '%')
</select>
<select id="selectIds" resultType="io.metersphere.api.dto.automation.ApiScenarioDTO">
select api_scenario.*, project_version.name as version_name, project.version_enable
from api_scenario
@ -446,13 +441,6 @@
</foreach>
</select>
<select id="selectByNoReferenceId" resultType="io.metersphere.base.domain.ApiScenarioWithBLOBs">
select *
from api_scenario
where id not in
(SELECT api_scenario_id FROM api_scenario_reference_id)
</select>
<select id="selectByIds" resultType="io.metersphere.base.domain.ApiScenarioWithBLOBs">
select *
from api_scenario
@ -530,17 +518,6 @@
#{v}
</foreach>
</update>
<update id="updateCustomNumByProjectId">
update api_scenario
set custom_num = num
where (custom_num is null or custom_num = '')
and project_id = #{projectId}
</update>
<update id="setScenarioEnvGroupIdNull">
update api_scenario
set environment_group_id = null
where environment_group_id = #{environmentGroupId}
</update>
<select id="countByProjectID" resultType="java.lang.Long">
SELECT COUNT(DISTINCT ref_id) AS countNumber
@ -583,14 +560,6 @@
GROUP BY groupField
</select>
<select id="selectIdsNotExistsInPlan" resultType="java.lang.String">
select c.id
from api_scenario c
where c.project_id = #{projectId}
and c.id not in (select pc.api_scenario_id
from test_plan_api_scenario pc
where pc.test_plan_id = #{planId})
</select>
<select id="getNextNum" resultType="io.metersphere.base.domain.ApiScenario">
SELECT *
FROM api_scenario
@ -604,26 +573,6 @@
left join project on api_scenario.project_id = project.id
<include refid="queryWhereCondition"/>
</select>
<select id="selectIdsByProjectId" resultType="java.lang.String">
select id
from api_scenario
WHERE project_id = #{0}
AND status != 'Trash'
</select>
<select id="listReview" resultMap="BaseResultMap">
select api_scenario.id, api_scenario.project_id, api_scenario.tags, api_scenario.user_id, api_scenario.num,
api_scenario.api_scenario_module_id,api_scenario.module_path, api_scenario.name, api_scenario.level,
api_scenario.status, api_scenario.principal, api_scenario.step_total,
api_scenario.last_result,api_scenario.pass_rate,api_scenario.report_id,
api_scenario.schedule, api_scenario.description, api_scenario.create_time, api_scenario.update_time,
project.name as project_name, user.name as user_name
from api_scenario
left join project on api_scenario.project_id = project.id
left join user on api_scenario.user_id = user.id
<include refid="queryWhereConditionReview"/>
<include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.orders"/>
</select>
<select id="selectTrash" resultType="java.lang.Integer">
select count(DISTINCT ref_id)
@ -633,38 +582,6 @@
and latest IS TRUE
</select>
<select id="selectNameById" resultType="java.lang.String">
select name
from api_scenario
WHERE id = #{0}
</select>
<select id="selectIdsByExecuteTimeIsNull" resultType="java.lang.String">
select id
from api_scenario
WHERE execute_times is null
OR execute_times = 0
</select>
<select id="selectNameByIdIn" resultType="java.lang.String">
select name
from api_scenario
WHERE id IN
<foreach collection="ids" item="v" separator="," open="(" close=")">
#{v}
</foreach>
</select>
<select id="countExecuteTimesByProjectID" resultType="java.lang.Long">
SELECT SUM(execute_times)
FROM api_scenario
WHERE project_id = #{0}
and latest = 1
</select>
<select id="selectProjectIds" resultType="java.lang.String">
select DISTINCT project_id
from api_scenario;
</select>
<select id="getIdsOrderByUpdateTime" resultType="java.lang.String">
select id
from api_scenario
@ -872,15 +789,6 @@
AND version_id != #{versionId}
</update>
<select id="selectRefIdsForVersionChange" resultType="java.lang.String">
SELECT DISTINCT ref_id
FROM api_scenario
WHERE ref_id NOT IN (SELECT DISTINCT ref_id
FROM api_scenario
WHERE version_id = #{versionId}
AND project_id = #{projectId})
AND project_id = #{projectId}
</select>
<select id="listWithRefIds" resultType="io.metersphere.base.domain.ApiScenarioWithBLOBs">
select id, project_id, version_id, scenario_definition, ref_id from api_scenario where ref_id in (
select distinct ref_id from api_scenario where id in
@ -889,11 +797,7 @@
</foreach>
)
</select>
<select id="selectByStatusIsNotTrash" resultType="io.metersphere.base.domain.ApiScenarioWithBLOBs">
SELECT *
FROM api_scenario
WHERE `status` != 'Trash' AND project_id IN (SELECT id FROM project);
</select>
<select id="selectRepeatByBLOBs" resultType="io.metersphere.base.domain.ApiScenarioWithBLOBs">
SELECT * from api_scenario
where name in

View File

@ -154,7 +154,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
Map<String, List<String>> filters = new LinkedHashMap<>();
filters.put(ApiTestConstants.STATUS, ApiTestConstants.STATUS_ALL);
request.setFilters(filters);
request.setModuleIds(new ArrayList<>());
if (StringUtils.isNotBlank(versionId)) {
request.setVersionId(versionId);
}

View File

@ -72,22 +72,10 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
Map<String, List<String>> filters = new LinkedHashMap<>();
filters.put(ApiTestConstants.STATUS, ApiTestConstants.STATUS_ALL);
request.setFilters(filters);
request.setModuleIds(new ArrayList<>());
List<ApiScenarioModuleDTO> moduleCountList = extApiScenarioMapper.listModuleByCollection(request);
return getNodeTrees(nodes, getCountMap(moduleCountList));
List<Map<String, Object>> moduleCountList = extApiScenarioMapper.listModuleByCollection(request);
Map<String, Integer> moduleCountMap = this.parseModuleCountList(moduleCountList);
for (ApiScenarioModuleDTO node : nodes) {
List<String> moduleIds = new ArrayList<>();
moduleIds = this.nodeList(nodes, node.getId(), moduleIds);
moduleIds.add(node.getId());
int countNum = 0;
for (String moduleId : moduleIds) {
if (moduleCountMap.containsKey(moduleId)) {
countNum += moduleCountMap.get(moduleId).intValue();
}
}
node.setCaseNum(countNum);
}
return getNodeTrees(nodes);
}
public List<ApiScenarioModuleDTO> getNodeTreeByProjectId(String projectId, ApiScenarioRequest request) {
@ -111,10 +99,10 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
//回收站数据初始化被删除了的数据挂在默认模块上
initTrashDataModule(projectId);
//通过回收站里的接口模块进行反显
if (request.getFilters() != null && request.getFilters().get("status") != null) {
if (request.getFilters() != null && request.getFilters().get(ApiTestConstants.STATUS) != null) {
List<String> statusList = new ArrayList<>();
statusList.add(ApiTestDataStatus.TRASH.getValue());
request.getFilters().put("status", statusList);
request.getFilters().put(ApiTestConstants.STATUS, statusList);
request.setModuleIds(null);
}
Map<String, List<ApiScenario>> trashApiMap = apiAutomationService.selectApiBaseInfoGroupByModuleId(projectId,
@ -166,23 +154,6 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
}
}
private Map<String, Integer> parseModuleCountList(List<Map<String, Object>> moduleCountList) {
Map<String, Integer> returnMap = new HashMap<>();
for (Map<String, Object> map : moduleCountList) {
Object moduleIdObj = map.get("moduleId");
Object countNumObj = map.get("countNum");
if (moduleIdObj != null && countNumObj != null) {
String moduleId = String.valueOf(moduleIdObj);
try {
Integer countNumInteger = new Integer(String.valueOf(countNumObj));
returnMap.put(moduleId, countNumInteger);
} catch (Exception e) {
}
}
}
return returnMap;
}
public static List<String> nodeList(List<ApiScenarioModuleDTO> nodes, String pid, List<String> list) {
for (ApiScenarioModuleDTO node : nodes) {
//遍历出父id等于参数的idadd进子节点集合

View File

@ -761,7 +761,7 @@ export default {
selectNodeIds() {
this.currentPage = 1;
this.$refs.scenarioTable.clear();
this.selectProjectId ? this.search(this.selectProjectId) : this.search();
this.selectProjectId ? this.nodeChange(this.selectProjectId) : this.nodeChange();
},
trashEnable() {
if (this.trashEnable) {
@ -831,8 +831,11 @@ export default {
});
}
},
search(projectId) {
search(projectId){
this.$EventBus.$emit('scenarioConditionBus', this.condition);
this.nodeChange(projectId);
},
nodeChange(projectId) {
if (this.needRefreshModule()) {
this.$emit('refreshTree');
}

View File

@ -54,7 +54,6 @@ import {
editScenarioModule,
getModuleByProjectId,
getModuleByRelevanceProjectId,
getModuleByTrash,
posScenarioModule,
postModuleByProjectId,
postModuleByTrash,
@ -172,13 +171,11 @@ export default {
created() {
this.$EventBus.$on('scenarioConditionBus', (param) => {
this.param = param;
this.list();
});
},
beforeDestroy() {
this.$EventBus.$off('scenarioConditionBus', (param) => {
this.param = param;
this.list();
});
},
methods: {
@ -291,7 +288,7 @@ export default {
} else {
this.$emit('nodeSelectEvent', node, nodeIds, pNodes);
}
this.nohupReloadTree(node.data.id);
// this.nohupReloadTree(node.data.id);
},
//
nohupReloadTree(selectNodeId) {

View File

@ -7,7 +7,6 @@ const install = function (Vue) {
install.installed = true;
// 遍历并注册全局组件
components.map((component) => {
console.log(component.name);
Vue.component(component.name, component);
});
};

View File

@ -179,13 +179,11 @@ export default {
created(){
this.$EventBus.$on("apiConditionBus", (param)=>{
this.param = param;
this.list();
})
},
beforeDestroy() {
this.$EventBus.$off("apiConditionBus", (param)=>{
this.param = param;
this.list();
})
},
methods: {
@ -333,7 +331,7 @@ export default {
} else {
this.$emit('nodeSelectEvent', node, nodeIds, pNodes);
}
this.nohupReloadTree(node.data.id);
// this.nohupReloadTree(node.data.id);
},
nohupReloadTree(selectNodeId) {
if (this.isRelevanceModel) {