refactor: 获取场景报告接口效率优化 (#9219)

Co-authored-by: chenjianxing <jianxing.chen@fit2cloud.com>
Co-authored-by: jianxing <41557596+AgAngle@users.noreply.github.com>
This commit is contained in:
metersphere-bot 2022-01-11 16:44:42 +08:00 committed by GitHub
parent 1711505409
commit deb9ad9670
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 11 deletions

View File

@ -133,7 +133,16 @@ public class ApiScenarioReportService {
public List<APIScenarioReportResult> list(QueryAPIReportRequest request) {
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
return extApiScenarioReportMapper.list(request);
List<APIScenarioReportResult> list = extApiScenarioReportMapper.list(request);
List<String> userIds = list.stream().map(APIScenarioReportResult::getUserId)
.collect(Collectors.toList());
Map<String, User> userMap = ServiceUtils.getUserMap(userIds);
list.forEach(item -> {
User user = userMap.get(item.getUserId());
if (user != null)
item.setUserName(user.getName());
});
return list;
}
public List<String> idList(QueryAPIReportRequest request) {

View File

@ -99,13 +99,10 @@
</sql>
<select id="list" resultMap="BaseResultMap">
SELECT r.name AS test_name,r.end_time,
r.name, r.description, r.id, r.project_id, r.create_time, r.update_time, r.status, r.trigger_mode,IfNULL(s.name,r.scenario_name) as scenario_name,
project.name AS project_name, user.name AS user_name
SELECT r.name AS test_name,r.end_time, r.user_id,
r.name, r.description, r.id, r.project_id, r.create_time, r.update_time, r.status, r.trigger_mode,IfNULL(s.name,r.scenario_name) as scenario_name
FROM api_scenario_report r
LEFT JOIN api_scenario s on r.scenario_id = s.id
LEFT JOIN project ON project.id = r.project_id
LEFT JOIN user ON user.id = r.user_id
<where>
<if test="request.combine != null">
<include refid="combine">
@ -121,10 +118,7 @@
AND r.user_id = #{request.userId,jdbcType=VARCHAR}
</if>
<if test="request.projectId != null">
AND project.id = #{request.projectId}
</if>
<if test="request.workspaceId != null">
AND project.workspace_id = #{request.workspaceId,jdbcType=VARCHAR}
AND r.project_id = #{request.projectId}
</if>
<if test="request.filters != null and request.filters.size() > 0">
<foreach collection="request.filters.entrySet()" index="key" item="values">

View File

@ -1,3 +1,6 @@
ALTER TABLE test_plan_report_content ADD plan_scenario_report_struct longtext NULL;
ALTER TABLE test_plan_report_content ADD plan_api_case_report_struct longtext NULL;
ALTER TABLE test_plan_report_content ADD plan_load_case_report_struct longtext NULL;
ALTER TABLE test_plan_report_content ADD plan_load_case_report_struct longtext NULL;
CREATE INDEX api_scenario_report_result_report_id_IDX ON api_scenario_report_result (report_id);