fix: 首页-过去七天失败用例数量查询速度过慢

修复首页-过去七天失败用例数量查询速度过慢的问题
This commit is contained in:
song.tianyang 2020-12-24 13:20:18 +08:00
parent ed68556937
commit 35462667e3
5 changed files with 28 additions and 25 deletions

View File

@ -188,11 +188,11 @@ public class ApiDataCountDTO {
for (ApiDataCountResult countResult : allExecuteResult) {
if("Success".equals(countResult.getGroupField())){
this.successCount+= countResult.getCountNumber();
}else if("Error".equals(countResult.getGroupField())){
this.executedCount+= countResult.getCountNumber();
}else if("Error".equals(countResult.getGroupField())||"Fail".equals(countResult.getGroupField())){
this.failedCount+= countResult.getCountNumber();
}
this.executedCount+= countResult.getCountNumber();
}
}
}
}

View File

@ -179,26 +179,29 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
testResult.setTestId(testId);
ApiScenarioReport scenarioReport = apiScenarioReportService.complete(testResult, this.runMode);
report = new ApiTestReport();
report.setStatus(scenarioReport.getStatus());
report.setId(scenarioReport.getId());
report.setTriggerMode(scenarioReport.getTriggerMode());
report.setName(scenarioReport.getName());
SystemParameterService systemParameterService = CommonBeanFactory.getBean(SystemParameterService.class);
assert systemParameterService != null;
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
reportUrl = baseSystemConfigDTO.getUrl() + "/#/api/automation/report";
String scenaName = scenarioReport.getName();
if (scenaName == null) {
scenaName = "";
} else {
String[] sceneNameArr = scenaName.split("-");
if (sceneNameArr.length >= 4) {
String endStr = "-" + sceneNameArr[sceneNameArr.length - 3] + "-" + sceneNameArr[sceneNameArr.length - 2] + "-" + sceneNameArr[sceneNameArr.length - 1];
scenaName = scenaName.split(endStr)[0];
} else {
scenaName = scenaName.split("-")[0];
}
}
String scenarioID = apiScenarioReportService.getApiScenarioId(scenaName, scenarioReport.getProjectId());
testResult.setTestId(scenarioID);

View File

@ -53,7 +53,7 @@
SELECT scene.`name` AS caseName,apiScene.testPlanName AS testPlan,count(report.id) AS failureTimes,'scenario' AS caseType
FROM api_scenario_report report
INNER JOIN api_scenario_report_detail reportDetail ON report.id = reportDetail.report_id
INNER JOIN api_scenario scene ON reportDetail.content like concat('%"', scene.`name`,'"%')
INNER JOIN api_scenario scene ON report.scenario_id = scene.id
LEFT JOIN
(
SELECT

View File

@ -179,8 +179,8 @@
SELECT count(acr.report_id) AS countNumber FROM api_scenario_report_detail acr
INNER JOIN api_scenario_report ar ON ar.id = acr.report_id
INNER JOIN (
SELECT acitem.`name` FROM api_scenario acitem INNER JOIN `schedule` sc ON acitem.id = sc.resource_id
) ac on acr.content like CONCAT('%"', ac.`name`,'"%')
SELECT acitem.`name`,acitem.id FROM api_scenario acitem INNER JOIN `schedule` sc ON acitem.id = sc.resource_id
) ac on ar.scenario_id = ac.id
WHERE acr.project_id = #{projectId} AND ar.create_time BETWEEN #{firstDayTimestamp} AND #{lastDayTimestamp}
</select>
@ -189,8 +189,8 @@
FROM api_scenario_report_detail acr
INNER JOIN api_scenario_report ar ON ar.id = acr.report_id
INNER JOIN (
SELECT acitem.`name` FROM api_scenario acitem INNER JOIN `schedule` sc ON acitem.id = sc.resource_id
) ac on acr.content like CONCAT('%"', ac.`name`,'"%')
SELECT acitem.`name`,acitem.id FROM api_scenario acitem INNER JOIN `schedule` sc ON acitem.id = sc.resource_id
) ac on ar.scenario_id = ac.id
WHERE acr.project_id = #{projectId}
</select>
</mapper>

View File

@ -38,17 +38,17 @@
<select id="countTaskByProjectId" resultType="java.lang.Long">
SELECT COUNT(id) AS countNumber FROM `schedule` WHERE resource_id IN (
SELECT id FROM api_test WHERE project_id = #{0,jdbcType=VARCHAR}
SELECT id FROM api_test WHERE project_id = #{0,jdbcType=VARCHAR} AND status != 'Trash'
UNION
SELECT id FROM api_scenario WHERE project_id = #{0,jdbcType=VARCHAR}
SELECT id FROM api_scenario WHERE project_id = #{0,jdbcType=VARCHAR} AND status != 'Trash'
)
</select>
<select id="countTaskByProjectIdAndCreateTimeRange" resultType="java.lang.Long">
SELECT COUNT(id) AS countNumber FROM `schedule`
WHERE resource_id IN (
SELECT id FROM api_test WHERE project_id = #{projectId,jdbcType=VARCHAR}
SELECT id FROM api_test WHERE project_id = #{projectId,jdbcType=VARCHAR} AND status != 'Trash'
UNION
SELECT id FROM api_scenario WHERE project_id = #{projectId,jdbcType=VARCHAR}
SELECT id FROM api_scenario WHERE project_id = #{projectId,jdbcType=VARCHAR} AND status != 'Trash'
)
AND create_time BETWEEN #{startTime} and #{endTime}
</select>