From d70bcdca41b24c5b478fde94b0dff048675332ae Mon Sep 17 00:00:00 2001 From: jianxing Date: Mon, 26 Jun 2023 11:50:44 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=B5=8B=E8=AF=95=E8=B7=9F=E8=B8=AA):?= =?UTF-8?q?=20=E5=8A=9F=E8=83=BD=E7=94=A8=E4=BE=8B=E5=88=97=E8=A1=A8?= =?UTF-8?q?=E4=B8=8D=E5=B1=95=E7=A4=BA=E6=96=87=E6=9C=AC=E6=A1=86=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E7=9A=84=E8=87=AA=E5=AE=9A=E4=B9=89=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=EF=BC=8C=E4=BC=98=E5=8C=96=E6=95=88=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1027283 --user=陈建星 【测试跟踪】github#25017,【功能用例】功能用例-自定义字段为“csc预期返回”和“csc请求参数”为大json串,当同种类型用例有50个用例,每页从默认切到50条,页面加载特别慢,至少得等1分钟 https://www.tapd.cn/55049933/s/1386041 --- .../ext/BaseCustomFieldResourceMapper.java | 2 ++ .../ext/BaseCustomFieldResourceMapper.xml | 9 ++++++++ .../service/CustomFieldResourceService.java | 21 +++++++++++++++++++ .../TestCaseTemplateController.java | 5 +++++ .../service/TestCaseTemplateService.java | 9 ++++++++ .../plan/service/TestPlanTestCaseService.java | 2 +- .../service/CustomFieldTestCaseService.java | 4 ++-- .../metersphere/service/TestCaseService.java | 2 +- .../frontend/src/api/custom-field-template.js | 4 ++++ .../business/case/components/TestCaseList.vue | 4 ++-- .../functional/FunctionalTestCaseList.vue | 5 ++--- 11 files changed, 58 insertions(+), 9 deletions(-) diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/base/mapper/ext/BaseCustomFieldResourceMapper.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/base/mapper/ext/BaseCustomFieldResourceMapper.java index a47ba08615..c26c6848b9 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/base/mapper/ext/BaseCustomFieldResourceMapper.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/base/mapper/ext/BaseCustomFieldResourceMapper.java @@ -19,6 +19,8 @@ public interface BaseCustomFieldResourceMapper { List getByResourceIds(@Param("tableName") String tableName, @Param("resourceIds") List resourceIds); + List getByResourceIdsForList(@Param("tableName") String tableName, @Param("resourceIds") List 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 resourceIds, @Param("record") CustomFieldResourceDTO customField); diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/base/mapper/ext/BaseCustomFieldResourceMapper.xml b/framework/sdk-parent/sdk/src/main/java/io/metersphere/base/mapper/ext/BaseCustomFieldResourceMapper.xml index d482bb6228..c50a3e5bb2 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/base/mapper/ext/BaseCustomFieldResourceMapper.xml +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/base/mapper/ext/BaseCustomFieldResourceMapper.xml @@ -88,4 +88,13 @@ + diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/CustomFieldResourceService.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/CustomFieldResourceService.java index f4a76ca1ac..d56ebaac51 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/CustomFieldResourceService.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/service/CustomFieldResourceService.java @@ -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 getByResourceIdsForList(String tableName, List resourceIds) { + if (CollectionUtils.isEmpty(resourceIds)) { + return new ArrayList<>(); + } + return baseCustomFieldResourceMapper.getByResourceIdsForList(tableName, resourceIds); + } + protected Map> getMapByResourceIds(String tableName, List resourceIds) { if (CollectionUtils.isEmpty(resourceIds)) { return new HashMap<>(); } List CustomFieldResourceDTOs = getByResourceIds(tableName, resourceIds); + return getFieldMap(CustomFieldResourceDTOs); + } + + protected Map> getMapByResourceIdsForList(String tableName, List resourceIds) { + if (CollectionUtils.isEmpty(resourceIds)) { + return new HashMap<>(); + } + List CustomFieldResourceDTOs = getByResourceIdsForList(tableName, resourceIds); + return getFieldMap(CustomFieldResourceDTOs); + } + + @NotNull + private static Map> getFieldMap(List CustomFieldResourceDTOs) { Map> fieldMap = new HashMap<>(); CustomFieldResourceDTOs.forEach(i -> { List fields = fieldMap.get(i.getResourceId()); diff --git a/project-management/backend/src/main/java/io/metersphere/controller/TestCaseTemplateController.java b/project-management/backend/src/main/java/io/metersphere/controller/TestCaseTemplateController.java index f9ff0e74f1..cbd72a58e9 100644 --- a/project-management/backend/src/main/java/io/metersphere/controller/TestCaseTemplateController.java +++ b/project-management/backend/src/main/java/io/metersphere/controller/TestCaseTemplateController.java @@ -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); + } } diff --git a/project-management/backend/src/main/java/io/metersphere/service/TestCaseTemplateService.java b/project-management/backend/src/main/java/io/metersphere/service/TestCaseTemplateService.java index 5ded253f79..50e8423d45 100644 --- a/project-management/backend/src/main/java/io/metersphere/service/TestCaseTemplateService.java +++ b/project-management/backend/src/main/java/io/metersphere/service/TestCaseTemplateService.java @@ -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) { diff --git a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanTestCaseService.java b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanTestCaseService.java index 72806f463e..f9c655ac53 100644 --- a/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanTestCaseService.java +++ b/test-track/backend/src/main/java/io/metersphere/plan/service/TestPlanTestCaseService.java @@ -108,7 +108,7 @@ public class TestPlanTestCaseService { ServiceUtils.buildCombineTagsToSupportMultiple(request); List list = extTestPlanTestCaseMapper.list(request); Map> 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)) { // 设置版本信息 diff --git a/test-track/backend/src/main/java/io/metersphere/service/CustomFieldTestCaseService.java b/test-track/backend/src/main/java/io/metersphere/service/CustomFieldTestCaseService.java index 584f5c0214..08fd1a771f 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/CustomFieldTestCaseService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/CustomFieldTestCaseService.java @@ -38,8 +38,8 @@ public class CustomFieldTestCaseService extends CustomFieldResourceService { super.deleteByResourceIds(TABLE_NAME, resourceIds); } - public Map> getMapByResourceIds(List resourceIds) { - return super.getMapByResourceIds(TABLE_NAME, resourceIds); + public Map> getMapByResourceIdsForList(List resourceIds) { + return super.getMapByResourceIdsForList(TABLE_NAME, resourceIds); } public List getByResourceId(String resourceId) { diff --git a/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java b/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java index 7e1736fe44..20169f9508 100644 --- a/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java +++ b/test-track/backend/src/main/java/io/metersphere/service/TestCaseService.java @@ -829,7 +829,7 @@ public class TestCaseService { return; } Map> 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()))); } diff --git a/test-track/frontend/src/api/custom-field-template.js b/test-track/frontend/src/api/custom-field-template.js index 4cd36e3331..fa16bade5e 100644 --- a/test-track/frontend/src/api/custom-field-template.js +++ b/test-track/frontend/src/api/custom-field-template.js @@ -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); } diff --git a/test-track/frontend/src/business/case/components/TestCaseList.vue b/test-track/frontend/src/business/case/components/TestCaseList.vue index 7ba23eb53d..f16e1fc891 100644 --- a/test-track/frontend/src/business/case/components/TestCaseList.vue +++ b/test-track/frontend/src/business/case/components/TestCaseList.vue @@ -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]; diff --git a/test-track/frontend/src/business/plan/view/comonents/functional/FunctionalTestCaseList.vue b/test-track/frontend/src/business/plan/view/comonents/functional/FunctionalTestCaseList.vue index f9cbd461d8..7a2816c9be 100644 --- a/test-track/frontend/src/business/plan/view/comonents/functional/FunctionalTestCaseList.vue +++ b/test-track/frontend/src/business/plan/view/comonents/functional/FunctionalTestCaseList.vue @@ -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;