fix(测试跟踪): 功能用例列表查询与批量删除性能优化
--bug=1013542 --user=陈建星 【测试跟踪】功能用例删除模块用例过多时,接口响应时间过长,需要优化性能 https://www.tapd.cn/55049933/s/1173692 --bug=1013347 --user=陈建星 【测试跟踪】windows电脑 8G 内存,测试跟踪功能用例 每条50页,翻页响应时间过长 需要优化性能 https://www.tapd.cn/55049933/s/1174023
This commit is contained in:
parent
22340b870e
commit
7dc82c72dc
|
@ -6,6 +6,7 @@ import io.metersphere.controller.request.BaseQueryRequest;
|
||||||
import io.metersphere.dto.RelationshipGraphData;
|
import io.metersphere.dto.RelationshipGraphData;
|
||||||
import io.metersphere.track.dto.CustomFieldResourceCompatibleDTO;
|
import io.metersphere.track.dto.CustomFieldResourceCompatibleDTO;
|
||||||
import io.metersphere.track.dto.TestCaseDTO;
|
import io.metersphere.track.dto.TestCaseDTO;
|
||||||
|
import io.metersphere.track.request.testcase.DeleteTestCaseRequest;
|
||||||
import io.metersphere.track.request.testcase.QueryTestCaseRequest;
|
import io.metersphere.track.request.testcase.QueryTestCaseRequest;
|
||||||
import io.metersphere.track.request.testcase.TestCaseBatchRequest;
|
import io.metersphere.track.request.testcase.TestCaseBatchRequest;
|
||||||
import io.metersphere.track.response.TrackCountResult;
|
import io.metersphere.track.response.TrackCountResult;
|
||||||
|
@ -109,7 +110,7 @@ public interface ExtTestCaseMapper {
|
||||||
|
|
||||||
List<TestCaseWithBLOBs> getCustomFieldsByIds(@Param("ids") List<String> ids);
|
List<TestCaseWithBLOBs> getCustomFieldsByIds(@Param("ids") List<String> ids);
|
||||||
|
|
||||||
int deleteToGc(@Param("request") TestCase testCase);
|
int deleteToGc(@Param("request") DeleteTestCaseRequest testCase);
|
||||||
|
|
||||||
int deletePublic(@Param("request") TestCase testCase);
|
int deletePublic(@Param("request") TestCase testCase);
|
||||||
|
|
||||||
|
|
|
@ -560,11 +560,11 @@
|
||||||
</if>
|
</if>
|
||||||
|
|
||||||
<if test="request.statusIsNot != null">
|
<if test="request.statusIsNot != null">
|
||||||
and (test_case.status is null or test_case.status != #{request.statusIsNot})
|
and test_case.status != #{request.statusIsNot}
|
||||||
</if>
|
</if>
|
||||||
|
|
||||||
<if test="request.notEqStatus != null">
|
<if test="request.notEqStatus != null">
|
||||||
and (test_case.status is null or test_case.status != #{request.notEqStatus})
|
and test_case.status != #{request.notEqStatus}
|
||||||
</if>
|
</if>
|
||||||
<if test="request.casePublic != null and request.casePublic == true">
|
<if test="request.casePublic != null and request.casePublic == true">
|
||||||
and test_case.case_public = true
|
and test_case.case_public = true
|
||||||
|
@ -621,11 +621,11 @@
|
||||||
</if>
|
</if>
|
||||||
|
|
||||||
<if test="request.statusIsNot != null">
|
<if test="request.statusIsNot != null">
|
||||||
and (test_case.status is null or test_case.status != #{request.statusIsNot})
|
and test_case.status != #{request.statusIsNot}
|
||||||
</if>
|
</if>
|
||||||
|
|
||||||
<if test="request.notEqStatus != null">
|
<if test="request.notEqStatus != null">
|
||||||
and (test_case.status is null or test_case.status != #{request.notEqStatus})
|
and test_case.status != #{request.notEqStatus}
|
||||||
</if>
|
</if>
|
||||||
<if test="request.name != null">
|
<if test="request.name != null">
|
||||||
and (test_case.name like CONCAT('%', #{request.name},'%')
|
and (test_case.name like CONCAT('%', #{request.name},'%')
|
||||||
|
@ -675,7 +675,7 @@
|
||||||
SELECT test_case.priority as groupField, count(DISTINCT ref_id) AS countNumber
|
SELECT test_case.priority as groupField, count(DISTINCT ref_id) AS countNumber
|
||||||
FROM test_case
|
FROM test_case
|
||||||
WHERE project_id = #{projectId}
|
WHERE project_id = #{projectId}
|
||||||
AND (test_case.status IS NULL OR test_case.status != 'Trash')
|
AND test_case.status != 'Trash'
|
||||||
and latest = true
|
and latest = true
|
||||||
GROUP BY test_case.priority
|
GROUP BY test_case.priority
|
||||||
</select>
|
</select>
|
||||||
|
@ -686,7 +686,7 @@
|
||||||
</select>
|
</select>
|
||||||
<select id="countStatus" resultType="io.metersphere.track.response.TrackCountResult">
|
<select id="countStatus" resultType="io.metersphere.track.response.TrackCountResult">
|
||||||
SELECT review_status AS groupField,count(id) AS countNumber FROM test_case
|
SELECT review_status AS groupField,count(id) AS countNumber FROM test_case
|
||||||
WHERE project_id = #{projectId} and (test_case.status != 'Trash' or test_case.status is null) and latest = 1
|
WHERE project_id = #{projectId} and test_case.status != 'Trash' and latest = 1
|
||||||
GROUP BY test_case.review_status
|
GROUP BY test_case.review_status
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
@ -887,7 +887,7 @@
|
||||||
<foreach collection="ids" item="id" separator="," open="(" close=")">
|
<foreach collection="ids" item="id" separator="," open="(" close=")">
|
||||||
#{id}
|
#{id}
|
||||||
</foreach>
|
</foreach>
|
||||||
and (test_case.status != 'Trash' or test_case.status is NULL);
|
and test_case.status != 'Trash';
|
||||||
</select>
|
</select>
|
||||||
<select id="countByIds" resultType="java.lang.Integer">
|
<select id="countByIds" resultType="java.lang.Integer">
|
||||||
select count(id)
|
select count(id)
|
||||||
|
@ -896,7 +896,7 @@
|
||||||
<foreach collection="ids" item="id" separator="," open="(" close=")">
|
<foreach collection="ids" item="id" separator="," open="(" close=")">
|
||||||
#{id}
|
#{id}
|
||||||
</foreach>
|
</foreach>
|
||||||
and (test_case.status != 'Trash' or test_case.status is NULL);
|
and test_case.status != 'Trash';
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<update id="deleteToGc">
|
<update id="deleteToGc">
|
||||||
|
@ -905,7 +905,24 @@
|
||||||
status = 'Trash',
|
status = 'Trash',
|
||||||
delete_time = #{request.deleteTime},
|
delete_time = #{request.deleteTime},
|
||||||
delete_user_id = #{request.deleteUserId}
|
delete_user_id = #{request.deleteUserId}
|
||||||
where ref_id = (select a.ref_id from (select ref_id from test_case where id = #{request.id}) a )
|
where ref_id in (
|
||||||
|
select a.ref_id from (
|
||||||
|
select ref_id from test_case
|
||||||
|
|
||||||
|
<where>
|
||||||
|
<if test="request.id != null and request.id != ''">
|
||||||
|
id = #{request.id}
|
||||||
|
</if>
|
||||||
|
<if test="request.ids != null and request.ids.size() != 0">
|
||||||
|
and id in
|
||||||
|
<foreach collection="request.ids" item="id" separator="," open="(" close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
|
||||||
|
) a
|
||||||
|
)
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
<update id="deletePublic">
|
<update id="deletePublic">
|
||||||
|
@ -936,7 +953,7 @@
|
||||||
update test_case
|
update test_case
|
||||||
set
|
set
|
||||||
original_status = 'Underway'
|
original_status = 'Underway'
|
||||||
where (original_status IS NULL OR original_status = 'Trash') AND id in
|
where (original_status = '' OR original_status = 'Trash') AND id in
|
||||||
<foreach collection="ids" item="v" separator="," open="(" close=")">
|
<foreach collection="ids" item="v" separator="," open="(" close=")">
|
||||||
#{v}
|
#{v}
|
||||||
</foreach>
|
</foreach>
|
||||||
|
@ -966,7 +983,7 @@
|
||||||
from project
|
from project
|
||||||
where workspace_id = #{workSpaceId})
|
where workspace_id = #{workSpaceId})
|
||||||
and case_public = true
|
and case_public = true
|
||||||
and (test_case.status != 'Trash' or test_case.status is NULL)
|
and test_case.status != 'Trash'
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="trashCount" resultType="java.lang.Long">
|
<select id="trashCount" resultType="java.lang.Long">
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package io.metersphere.track.request.testcase;
|
||||||
|
|
||||||
|
import io.metersphere.base.domain.TestCase;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class DeleteTestCaseRequest extends TestCase {
|
||||||
|
private List<String> ids;
|
||||||
|
}
|
|
@ -232,12 +232,35 @@ public class TestCaseService {
|
||||||
updateRequest.setProjectId(request.getProjectId());
|
updateRequest.setProjectId(request.getProjectId());
|
||||||
updateRequest.setTestCaseId(request.getId());
|
updateRequest.setTestCaseId(request.getId());
|
||||||
Project project = projectService.getProjectById(request.getProjectId());
|
Project project = projectService.getProjectById(request.getProjectId());
|
||||||
|
if (StringUtils.equals(project.getPlatform(), IssuesManagePlatform.AzureDevops.name())) {
|
||||||
updateRequest.setWorkspaceId(project.getWorkspaceId());
|
updateRequest.setWorkspaceId(project.getWorkspaceId());
|
||||||
List<AbstractIssuePlatform> platformList = getAddPlatforms(updateRequest);
|
List<AbstractIssuePlatform> platformList = getAddPlatforms(updateRequest);
|
||||||
platformList.forEach(platform -> {
|
platformList.forEach(platform -> {
|
||||||
platform.updateDemandHyperLink(request, project, type);
|
platform.updateDemandHyperLink(request, project, type);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDemandHyperLinkBatch(List<String> testcaseIds) {
|
||||||
|
if (CollectionUtils.isEmpty(testcaseIds)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
TestCaseWithBLOBs testCase = testCaseMapper.selectByPrimaryKey(testcaseIds.get(0));
|
||||||
|
// 同步删除用例与需求的关联关系
|
||||||
|
Project project = projectService.getProjectById(testCase.getProjectId());
|
||||||
|
|
||||||
|
// AzureDevops 才处理
|
||||||
|
if (StringUtils.equals(project.getPlatform(), IssuesManagePlatform.AzureDevops.name())) {
|
||||||
|
testcaseIds.forEach(id -> {
|
||||||
|
TestCaseWithBLOBs testCaseWithBLOBs = testCaseMapper.selectByPrimaryKey(testcaseIds.get(0));
|
||||||
|
if (testCaseWithBLOBs != null) {
|
||||||
|
EditTestCaseRequest request = new EditTestCaseRequest();
|
||||||
|
BeanUtils.copyBean(request, testCaseWithBLOBs);
|
||||||
|
addDemandHyperLink(request, "delete");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private List<AbstractIssuePlatform> getAddPlatforms(IssuesRequest request) {
|
private List<AbstractIssuePlatform> getAddPlatforms(IssuesRequest request) {
|
||||||
List<String> platforms = new ArrayList<>();
|
List<String> platforms = new ArrayList<>();
|
||||||
|
@ -612,7 +635,25 @@ public class TestCaseService {
|
||||||
addDemandHyperLink(request, "delete");
|
addDemandHyperLink(request, "delete");
|
||||||
}
|
}
|
||||||
|
|
||||||
return extTestCaseMapper.deleteToGc(testCase);
|
DeleteTestCaseRequest request = new DeleteTestCaseRequest();
|
||||||
|
BeanUtils.copyBean(request, testCase);
|
||||||
|
return extTestCaseMapper.deleteToGc(request);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int deleteToGcBatch(List<String> ids) {
|
||||||
|
if (CollectionUtils.isEmpty(ids)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
TestCase testCase = new TestCase();
|
||||||
|
testCase.setDeleteUserId(SessionUtils.getUserId());
|
||||||
|
testCase.setDeleteTime(System.currentTimeMillis());
|
||||||
|
|
||||||
|
addDemandHyperLinkBatch(ids);
|
||||||
|
|
||||||
|
DeleteTestCaseRequest request = new DeleteTestCaseRequest();
|
||||||
|
BeanUtils.copyBean(request, testCase);
|
||||||
|
request.setIds(ids);
|
||||||
|
return extTestCaseMapper.deleteToGc(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<TestCaseDTO> listTestCase(QueryTestCaseRequest request) {
|
public List<TestCaseDTO> listTestCase(QueryTestCaseRequest request) {
|
||||||
|
@ -678,11 +719,6 @@ public class TestCaseService {
|
||||||
|
|
||||||
public void setDefaultOrder(QueryTestCaseRequest request) {
|
public void setDefaultOrder(QueryTestCaseRequest request) {
|
||||||
List<OrderRequest> orders = ServiceUtils.getDefaultSortOrder(request.getOrders());
|
List<OrderRequest> orders = ServiceUtils.getDefaultSortOrder(request.getOrders());
|
||||||
OrderRequest order = new OrderRequest();
|
|
||||||
// 对模板导入的测试用例排序
|
|
||||||
order.setName("sort");
|
|
||||||
order.setType("desc");
|
|
||||||
orders.add(order);
|
|
||||||
orders.forEach(i -> i.setPrefix("test_case"));
|
orders.forEach(i -> i.setPrefix("test_case"));
|
||||||
request.setOrders(orders);
|
request.setOrders(orders);
|
||||||
}
|
}
|
||||||
|
@ -1058,7 +1094,7 @@ public class TestCaseService {
|
||||||
num++;
|
num++;
|
||||||
testCase.setReviewStatus(TestCaseReviewStatus.Prepare.name());
|
testCase.setReviewStatus(TestCaseReviewStatus.Prepare.name());
|
||||||
testCase.setStatus(TestCaseReviewStatus.Prepare.name());
|
testCase.setStatus(TestCaseReviewStatus.Prepare.name());
|
||||||
testCase.setOrder(new Long(testCases.size() - (num - beforeInsertId)) * ServiceUtils.ORDER_STEP);
|
testCase.setOrder(Long.valueOf(testCases.size() - (num - beforeInsertId)) * ServiceUtils.ORDER_STEP);
|
||||||
testCase.setRefId(testCase.getId());
|
testCase.setRefId(testCase.getId());
|
||||||
testCase.setVersionId(request.getVersionId());
|
testCase.setVersionId(request.getVersionId());
|
||||||
testCase.setLatest(true);
|
testCase.setLatest(true);
|
||||||
|
@ -1131,11 +1167,9 @@ public class TestCaseService {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!testCases.isEmpty()) {
|
if (!testCases.isEmpty()) {
|
||||||
AtomicInteger sort = new AtomicInteger();
|
|
||||||
testCases.forEach(testcase -> {
|
testCases.forEach(testcase -> {
|
||||||
testcase.setUpdateTime(System.currentTimeMillis());
|
testcase.setUpdateTime(System.currentTimeMillis());
|
||||||
testcase.setNodeId(nodePathMap.get(testcase.getNodePath()));
|
testcase.setNodeId(nodePathMap.get(testcase.getNodePath()));
|
||||||
testcase.setSort(sort.getAndIncrement());
|
|
||||||
TestCase dbCase = request.isUseCustomId() ? customIdMap.get(testcase.getCustomNum()) : customIdMap.get(testcase.getNum());
|
TestCase dbCase = request.isUseCustomId() ? customIdMap.get(testcase.getCustomNum()) : customIdMap.get(testcase.getNum());
|
||||||
testcase.setId(dbCase.getId());
|
testcase.setId(dbCase.getId());
|
||||||
testcase.setRefId(dbCase.getRefId());
|
testcase.setRefId(dbCase.getRefId());
|
||||||
|
@ -2221,14 +2255,6 @@ public class TestCaseService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void deleteToGcBatch(List<String> ids) {
|
|
||||||
if (CollectionUtils.isNotEmpty(ids)) {
|
|
||||||
for (String id : ids) {
|
|
||||||
this.deleteTestCaseToGc(id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void deleteToGcBatchPublic(TestCaseBatchRequest request) {
|
public void deleteToGcBatchPublic(TestCaseBatchRequest request) {
|
||||||
ServiceUtils.getSelectAllIds(request, request.getCondition(),
|
ServiceUtils.getSelectAllIds(request, request.getCondition(),
|
||||||
(query) -> extTestCaseMapper.selectPublicIds(query));
|
(query) -> extTestCaseMapper.selectPublicIds(query));
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
-- 初始化 sql
|
Loading…
Reference in New Issue