refactor(接口测试): 优化接口模块树加载效率
--story=1011189 --user=赵勇 系统左侧模块树加载效率优化 https://www.tapd.cn/55049933/s/1343693
This commit is contained in:
parent
24c07db714
commit
78a1e9deb6
|
@ -1,40 +1,26 @@
|
|||
package io.metersphere.base.mapper.ext;
|
||||
|
||||
import io.metersphere.api.dto.datacount.ApiDataCountResult;
|
||||
import io.metersphere.api.dto.definition.ApiComputeResult;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionRequest;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionResult;
|
||||
import io.metersphere.api.dto.definition.ApiSwaggerUrlDTO;
|
||||
import io.metersphere.api.dto.definition.*;
|
||||
import io.metersphere.base.domain.*;
|
||||
import io.metersphere.dto.RelationshipGraphData;
|
||||
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 ExtApiDefinitionMapper {
|
||||
List<ApiSwaggerUrlDTO> selectScheduleList(@Param("projectId") String projectId);
|
||||
|
||||
List<ApiDefinitionResult> list(@Param("request") ApiDefinitionRequest request);
|
||||
|
||||
List<ApiDefinitionWithBLOBs> apiList(@Param("request") ApiDefinitionRequest request);
|
||||
|
||||
List<ApiDefinitionResult> weekList(@Param("request") ApiDefinitionRequest request, @Param("startTimestamp") long startTimestamp);
|
||||
|
||||
List<ApiScenario> scenarioList(@Param("apiDefinitionId") String apiDefinitionId);
|
||||
|
||||
int moduleCount(@Param("request") ApiDefinitionRequest request);
|
||||
|
||||
//List<ApiComputeResult> selectByIds(@Param("ids") List<String> ids);
|
||||
|
||||
List<ApiComputeResult> selectByIds(@Param("ids") List<String> ids, @Param("projectId") String projectId);
|
||||
|
||||
List<ApiComputeResult> selectByIdsAndStatusIsNotTrash(@Param("ids") List<String> ids, @Param("projectId") String projectId);
|
||||
|
||||
// int removeToGc(@Param("ids") List<String> ids);
|
||||
|
||||
int removeToGcByExample(ApiDefinitionExampleWithOperation example);
|
||||
|
||||
int reduction(@Param("ids") List<String> ids);
|
||||
|
@ -59,14 +45,10 @@ public interface ExtApiDefinitionMapper {
|
|||
|
||||
List<ApiDefinitionResult> listByIds(@Param("ids") List<String> ids);
|
||||
|
||||
List<Map<String, Object>> moduleCountByCollection(@Param("request") ApiDefinitionRequest request);
|
||||
|
||||
ApiDefinition selectUrlAndMethodById(String id);
|
||||
List<ApiModuleDTO> moduleCountByCollection(@Param("request") ApiDefinitionRequest request);
|
||||
|
||||
int checkOriginalStatusByIds(@Param("ids") List<String> ids);
|
||||
|
||||
List<String> selectProjectIds();
|
||||
|
||||
List<String> getIdsOrderByUpdateTime(@Param("projectId") String projectId);
|
||||
|
||||
Long getPreOrder(@Param("projectId") String projectId, @Param("baseOrder") Long baseOrder);
|
||||
|
@ -87,20 +69,14 @@ public interface ExtApiDefinitionMapper {
|
|||
|
||||
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);
|
||||
|
||||
String selectNameById(String testId);
|
||||
|
||||
int toBeUpdateApi(@Param("ids") List<String> ids, @Param("toBeUpdate") Boolean toBeUpdate);
|
||||
|
||||
List<ApiDefinitionWithBLOBs> selectRepeatByBLOBs(@Param("blobs") List<ApiDefinitionWithBLOBs> blobs, @Param("projectId") String projectId);
|
||||
|
||||
List<ApiDefinitionWithBLOBs> selectRepeatByBLOBsSameUrl(@Param("blobs") List<ApiDefinitionWithBLOBs> blobs, @Param("projectId") String projectId, @Param("moduleId") String moduleId);
|
||||
|
||||
List<ApiDefinitionWithBLOBs> selectRepeatByProtocol(@Param("names") List<String> names, @Param("protocol") String protocol, @Param("projectId") String projectId);
|
||||
|
||||
int countById(String id);
|
||||
|
||||
List<ApiDefinition> selectEffectiveIdByProjectIdAndHaveNotCase(@Param("projectId") String projectId, @Param("versionId") String versionId);
|
||||
|
||||
int deleteApiToGc(ApiDefinitionRequest request);
|
||||
|
|
|
@ -460,11 +460,7 @@
|
|||
WHERE api_definition.project_id = #{projectId}
|
||||
ORDER BY num DESC LIMIT 1;
|
||||
</select>
|
||||
<select id="selectUrlAndMethodById" resultType="io.metersphere.base.domain.ApiDefinition">
|
||||
SELECT method, path
|
||||
FROM api_definition
|
||||
WHERE id = #{0}
|
||||
</select>
|
||||
|
||||
<select id="listRelevance" resultType="io.metersphere.api.dto.definition.ApiDefinitionResult">
|
||||
select
|
||||
api_definition.version_id versionId,
|
||||
|
@ -665,21 +661,6 @@
|
|||
</if>
|
||||
</select>
|
||||
|
||||
<select id="selectScheduleList" resultType="io.metersphere.api.dto.definition.ApiSwaggerUrlDTO">
|
||||
SELECT apiScene.id AS scenarioId,
|
||||
apiScene.`name` AS `name`,
|
||||
sch.id AS taskID,
|
||||
sch.`value` AS rule,
|
||||
sch.`enable` AS `taskStatus`,
|
||||
u.`name` AS creator,
|
||||
sch.update_time AS updateTime,
|
||||
'scenario' AS taskType
|
||||
FROM api_scenario apiScene
|
||||
INNER JOIN `schedule` sch ON apiScene.id = sch.resource_id
|
||||
INNER JOIN `user` u ON u.id = sch.user_id
|
||||
WHERE sch.`enable` = true
|
||||
AND apiScene.project_id = #{0,jdbcType=VARCHAR}
|
||||
</select>
|
||||
<select id="selectIds" resultType="java.lang.String">
|
||||
select api_definition.id
|
||||
from api_definition
|
||||
|
@ -714,13 +695,9 @@
|
|||
AND id NOT IN (select api_definition_id FROM api_test_case WHERE project_id = #{projectId}
|
||||
AND (status IS NULL or status != 'Trash'))
|
||||
</select>
|
||||
<select id="moduleCount" resultType="java.lang.Integer">
|
||||
select count(id) from api_definition
|
||||
<include refid="queryWhereCondition"/>
|
||||
</select>
|
||||
|
||||
<select id="moduleCountByCollection" resultType="java.util.Map">
|
||||
select module_id AS moduleId,count(id) AS countNum from api_definition
|
||||
<select id="moduleCountByCollection" resultType="io.metersphere.api.dto.definition.ApiModuleDTO">
|
||||
select module_id AS id,count(id) AS caseNum from api_definition
|
||||
<include refid="queryWhereCondition"/>
|
||||
GROUP BY module_id
|
||||
</select>
|
||||
|
@ -1008,10 +985,6 @@
|
|||
</where>
|
||||
</sql>
|
||||
|
||||
<select id="selectProjectIds" resultType="java.lang.String">
|
||||
select DISTINCT project_id
|
||||
from api_definition;
|
||||
</select>
|
||||
<select id="getIdsOrderByUpdateTime" resultType="java.lang.String">
|
||||
select id
|
||||
from api_definition
|
||||
|
@ -1077,11 +1050,7 @@
|
|||
</foreach>
|
||||
and api_definition.status != 'Trash';
|
||||
</select>
|
||||
<select id="countById" resultType="java.lang.Integer">
|
||||
select count(id)
|
||||
from api_definition
|
||||
where id = #{0}
|
||||
</select>
|
||||
|
||||
<select id="countByExample" parameterType="io.metersphere.base.domain.ApiDefinitionExample"
|
||||
resultType="java.lang.Long">
|
||||
select count(DISTINCT ref_id) from api_definition
|
||||
|
@ -1143,16 +1112,6 @@
|
|||
WHERE ref_id = #{refId,jdbcType=VARCHAR}
|
||||
</update>
|
||||
|
||||
<update id="toBeUpdateApi">
|
||||
update api_definition
|
||||
set
|
||||
to_be_updated = #{toBeUpdate}
|
||||
where id in
|
||||
<foreach collection="ids" item="v" separator="," open="(" close=")">
|
||||
#{v}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<update id="updateNoModuleApiToDefaultModule">
|
||||
UPDATE api_definition
|
||||
SET module_id = #{moduleId}
|
||||
|
@ -1176,15 +1135,6 @@
|
|||
WHERE ref_id = #{refId}
|
||||
AND version_id != #{versionId}
|
||||
</update>
|
||||
<select id="selectRefIdsForVersionChange" resultType="java.lang.String">
|
||||
SELECT DISTINCT ref_id
|
||||
FROM api_definition
|
||||
WHERE ref_id NOT IN (SELECT DISTINCT ref_id
|
||||
FROM api_definition
|
||||
WHERE version_id = #{versionId}
|
||||
AND project_id = #{projectId})
|
||||
AND project_id = #{projectId}
|
||||
</select>
|
||||
|
||||
<select id="selectNameById" resultType="java.lang.String">
|
||||
SELECT name
|
||||
|
@ -1215,24 +1165,7 @@
|
|||
and project_id = #{projectId}
|
||||
and status != 'Trash'
|
||||
</select>
|
||||
<select id="apiList" resultType="io.metersphere.base.domain.ApiDefinitionWithBLOBs">
|
||||
select * from api_definition
|
||||
<include refid="queryWhereCondition"/>
|
||||
<if test="request.orders != null and request.orders.size() > 0">
|
||||
order by
|
||||
<foreach collection="request.orders" separator="," item="order">
|
||||
<if test="order.name == 'user_name'">
|
||||
user_name ${order.type}
|
||||
</if>
|
||||
<if test="order.name == 'case_total'">
|
||||
CONVERT(api_definition.${order.name},SIGNED) ${order.type}
|
||||
</if>
|
||||
<if test="order.name != 'user_name' and order.name != 'case_total'">
|
||||
api_definition.${order.name} ${order.type}
|
||||
</if>
|
||||
</foreach>
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="selectApiBaseInfoByProjectIdAndProtocolAndStatus" resultType="io.metersphere.base.domain.ApiDefinition">
|
||||
select id, module_id
|
||||
from api_definition
|
||||
|
|
|
@ -22,6 +22,7 @@ import io.metersphere.log.vo.DetailColumn;
|
|||
import io.metersphere.log.vo.OperatingLogDetails;
|
||||
import io.metersphere.log.vo.api.ModuleReference;
|
||||
import io.metersphere.service.NodeTreeService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -33,17 +34,7 @@ import org.mybatis.spring.SqlSessionUtils;
|
|||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
@ -167,41 +158,8 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
if (StringUtils.isNotBlank(versionId)) {
|
||||
request.setVersionId(versionId);
|
||||
}
|
||||
|
||||
List<Map<String, Object>> moduleCountList = extApiDefinitionMapper.moduleCountByCollection(request);
|
||||
Map<String, Integer> moduleCountMap = this.parseModuleCountList(moduleCountList);
|
||||
// 获取所有模块数ID
|
||||
for (ApiModuleDTO node : apiModules) {
|
||||
List<String> moduleIds = new ArrayList<>();
|
||||
this.nodeList(apiModules, 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(apiModules);
|
||||
}
|
||||
|
||||
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 = Integer.parseInt(String.valueOf(countNumObj));
|
||||
returnMap.put(moduleId, countNumInteger);
|
||||
} catch (Exception e) {
|
||||
LogUtil.error("method parseModuleCountList has error:", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnMap;
|
||||
List<ApiModuleDTO> countMNodes = extApiDefinitionMapper.moduleCountByCollection(request);
|
||||
return getNodeTrees(apiModules, getCountMap(countMNodes));
|
||||
}
|
||||
|
||||
public static void nodeList(List<ApiModuleDTO> apiNodes, String pid, List<String> list) {
|
||||
|
|
Loading…
Reference in New Issue