refactor(测试跟踪): 功能用例列表不展示文本框类型的自定义字段,优化效率

--bug=1027283 --user=陈建星 【测试跟踪】github#25017,【功能用例】功能用例-自定义字段为“csc预期返回”和“csc请求参数”为大json串,当同种类型用例有50个用例,每页从默认切到50条,页面加载特别慢,至少得等1分钟 https://www.tapd.cn/55049933/s/1386041
This commit is contained in:
jianxing 2023-06-26 11:50:44 +08:00 committed by 刘瑞斌
parent aefea087de
commit d70bcdca41
11 changed files with 58 additions and 9 deletions

View File

@ -19,6 +19,8 @@ public interface BaseCustomFieldResourceMapper {
List<CustomFieldResourceDTO> getByResourceIds(@Param("tableName") String tableName, @Param("resourceIds") List<String> resourceIds);
List<CustomFieldResourceDTO> getByResourceIdsForList(@Param("tableName") String tableName, @Param("resourceIds") List<String> resourceIds);
long countFieldResource(@Param("tableName") String tableName, @Param("resourceId") String resourceId, @Param("fieldId") String field_id);
int batchUpdateByResourceIds(@Param("tableName") String tableName, @Param("resourceIds") List<String> resourceIds, @Param("record") CustomFieldResourceDTO customField);

View File

@ -88,4 +88,13 @@
<select id="countFieldResource" resultType="java.lang.Long">
select count(1) from ${tableName} where resource_id = #{resourceId} and field_id = #{fieldId}
</select>
<select id="getByResourceIdsForList" resultType="io.metersphere.dto.CustomFieldResourceDTO">
select
<include refid="Base_Column_List" />
from ${tableName}
where resource_id in
<foreach collection="resourceIds" item="resourceId" separator="," open="(" close=")">
#{resourceId}
</foreach>
</select>
</mapper>

View File

@ -9,6 +9,7 @@ import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.jetbrains.annotations.NotNull;
import org.mybatis.spring.SqlSessionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -114,11 +115,31 @@ public class CustomFieldResourceService {
return baseCustomFieldResourceMapper.getByResourceIds(tableName, resourceIds);
}
protected List<CustomFieldResourceDTO> getByResourceIdsForList(String tableName, List<String> resourceIds) {
if (CollectionUtils.isEmpty(resourceIds)) {
return new ArrayList<>();
}
return baseCustomFieldResourceMapper.getByResourceIdsForList(tableName, resourceIds);
}
protected Map<String, List<CustomFieldDao>> getMapByResourceIds(String tableName, List<String> resourceIds) {
if (CollectionUtils.isEmpty(resourceIds)) {
return new HashMap<>();
}
List<CustomFieldResourceDTO> CustomFieldResourceDTOs = getByResourceIds(tableName, resourceIds);
return getFieldMap(CustomFieldResourceDTOs);
}
protected Map<String, List<CustomFieldDao>> getMapByResourceIdsForList(String tableName, List<String> resourceIds) {
if (CollectionUtils.isEmpty(resourceIds)) {
return new HashMap<>();
}
List<CustomFieldResourceDTO> CustomFieldResourceDTOs = getByResourceIdsForList(tableName, resourceIds);
return getFieldMap(CustomFieldResourceDTOs);
}
@NotNull
private static Map<String, List<CustomFieldDao>> getFieldMap(List<CustomFieldResourceDTO> CustomFieldResourceDTOs) {
Map<String, List<CustomFieldDao>> fieldMap = new HashMap<>();
CustomFieldResourceDTOs.forEach(i -> {
List<CustomFieldDao> fields = fieldMap.get(i.getResourceId());

View File

@ -68,4 +68,9 @@ public class TestCaseTemplateController {
public TestCaseTemplateDao getTemplate(@PathVariable String projectId) {
return testCaseTemplateService.getTemplate(projectId);
}
@GetMapping("/get/relate/simple/{projectId}")
public TestCaseTemplateDao getTemplateForList(@PathVariable String projectId) {
return testCaseTemplateService.getTemplateForList(projectId);
}
}

View File

@ -3,6 +3,7 @@ package io.metersphere.service;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.TestCaseTemplateMapper;
import io.metersphere.base.mapper.ext.ExtTestCaseTemplateMapper;
import io.metersphere.commons.constants.CustomFieldType;
import io.metersphere.commons.constants.TemplateConstants;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.BeanUtils;
@ -251,6 +252,14 @@ public class TestCaseTemplateService extends TemplateBaseService {
return caseTemplateDao;
}
public TestCaseTemplateDao getTemplateForList(String projectId) {
TestCaseTemplateDao template = getTemplate(projectId);
// 列表展示过滤掉文本框和富文本框等大字段否则加载效率低
template.getCustomFields().stream().filter(field ->
!StringUtils.equalsAnyIgnoreCase(field.getType(), CustomFieldType.TEXTAREA.getValue(), CustomFieldType.RICH_TEXT.getValue()));
return template;
}
public String getLogDetails(String id) {
TestCaseTemplateWithBLOBs templateWithBLOBs = testCaseTemplateMapper.selectByPrimaryKey(id);
if (templateWithBLOBs != null) {

View File

@ -108,7 +108,7 @@ public class TestPlanTestCaseService {
ServiceUtils.buildCombineTagsToSupportMultiple(request);
List<TestPlanCaseDTO> list = extTestPlanTestCaseMapper.list(request);
Map<String, List<CustomFieldDao>> fieldMap =
customFieldTestCaseService.getMapByResourceIds(list.stream().map(TestPlanCaseDTO::getCaseId).collect(Collectors.toList()));
customFieldTestCaseService.getMapByResourceIdsForList(list.stream().map(TestPlanCaseDTO::getCaseId).collect(Collectors.toList()));
list.forEach(i -> i.setFields(fieldMap.get(i.getCaseId())));
if (CollectionUtils.isNotEmpty(list)) {
// 设置版本信息

View File

@ -38,8 +38,8 @@ public class CustomFieldTestCaseService extends CustomFieldResourceService {
super.deleteByResourceIds(TABLE_NAME, resourceIds);
}
public Map<String, List<CustomFieldDao>> getMapByResourceIds(List<String> resourceIds) {
return super.getMapByResourceIds(TABLE_NAME, resourceIds);
public Map<String, List<CustomFieldDao>> getMapByResourceIdsForList(List<String> resourceIds) {
return super.getMapByResourceIdsForList(TABLE_NAME, resourceIds);
}
public List<CustomFieldResourceDTO> getByResourceId(String resourceId) {

View File

@ -829,7 +829,7 @@ public class TestCaseService {
return;
}
Map<String, List<CustomFieldDao>> fieldMap =
customFieldTestCaseService.getMapByResourceIds(data.stream().map(TestCaseDTO::getId).collect(Collectors.toList()));
customFieldTestCaseService.getMapByResourceIdsForList(data.stream().map(TestCaseDTO::getId).collect(Collectors.toList()));
data.forEach(i -> i.setFields(fieldMap.get(i.getId())));
}

View File

@ -27,6 +27,10 @@ export function getTestTemplate(projectId) {
return getTemplate('field/template/case/get/relate/', projectId);
}
export function getTestTemplateForList(projectId) {
return getTemplate('field/template/case/get/relate/simple/', projectId);
}
export function updateCustomFieldTemplate(request) {
return post('/custom/field/template/update', request);
}

View File

@ -284,7 +284,7 @@ import PlanStatusTableItem from "@/business/common/tableItems/plan/PlanStatusTab
import {getCurrentProjectID, getCurrentWorkspaceId, setCurrentProjectID} from "metersphere-frontend/src/utils/token";
import {parseTag} from "metersphere-frontend/src/utils"
import {hasLicense} from "metersphere-frontend/src/utils/permission"
import {getTestTemplate} from "@/api/custom-field-template";
import {getTestTemplateForList} from "@/api/custom-field-template";
import {getProjectMember, getProjectMemberUserFilter} from "@/api/user";
import MsTable from "metersphere-frontend/src/components/new-ui/MsTable";
import MsTableColumn from "metersphere-frontend/src/components/table/MsTableColumn";
@ -637,7 +637,7 @@ export default {
this.memberMap.set(item.id, item.name);
});
});
let p2 = getTestTemplate();
let p2 = getTestTemplateForList();
Promise.all([p1, p2]).then((data) => {
this.loading = false;
let template = data[1];

View File

@ -311,12 +311,11 @@ import {
initCondition,
getCustomFieldFilter,
parseCustomFilesForList,
getCustomFieldValue as _getCustomFieldValue,
} from "metersphere-frontend/src/utils/tableUtils";
import MsTable from "metersphere-frontend/src/components/table/MsTable";
import MsTableColumn from "metersphere-frontend/src/components/table/MsTableColumn";
import {getProjectMember} from "@/api/user";
import {getTestTemplate} from "@/api/custom-field-template";
import {getTestTemplateForList} from "@/api/custom-field-template";
import {
editTestPlanTestCaseOrder,
testPlanAutoCheck,
@ -581,7 +580,7 @@ export default {
.then((response) => {
this.members = response.data;
});
let p2 = getTestTemplate();
let p2 = getTestTemplateForList();
Promise.all([p1, p2]).then((data) => {
let template = data[1];
this.testCaseTemplate = template;