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) { for (ApiDataCountResult countResult : allExecuteResult) {
if("Success".equals(countResult.getGroupField())){ if("Success".equals(countResult.getGroupField())){
this.successCount+= countResult.getCountNumber(); 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.failedCount+= countResult.getCountNumber();
}
this.executedCount+= countResult.getCountNumber(); this.executedCount+= countResult.getCountNumber();
} }
} }
}
} }

View File

@ -179,28 +179,31 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
testResult.setTestId(testId); testResult.setTestId(testId);
ApiScenarioReport scenarioReport = apiScenarioReportService.complete(testResult, this.runMode); ApiScenarioReport scenarioReport = apiScenarioReportService.complete(testResult, this.runMode);
report = new ApiTestReport(); report = new ApiTestReport();
report.setStatus(scenarioReport.getStatus()); report.setStatus(scenarioReport.getStatus());
report.setId(scenarioReport.getId()); report.setId(scenarioReport.getId());
report.setTriggerMode(scenarioReport.getTriggerMode()); report.setTriggerMode(scenarioReport.getTriggerMode());
report.setName(scenarioReport.getName()); report.setName(scenarioReport.getName());
SystemParameterService systemParameterService = CommonBeanFactory.getBean(SystemParameterService.class); SystemParameterService systemParameterService = CommonBeanFactory.getBean(SystemParameterService.class);
assert systemParameterService != null; assert systemParameterService != null;
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo(); BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
reportUrl = baseSystemConfigDTO.getUrl() + "/#/api/automation/report"; reportUrl = baseSystemConfigDTO.getUrl() + "/#/api/automation/report";
String scenaName = scenarioReport.getName(); String scenaName = scenarioReport.getName();
if(scenaName==null){ if (scenaName == null) {
scenaName = ""; scenaName = "";
}else { } 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]; scenaName = scenaName.split("-")[0];
} }
}
String scenarioID = apiScenarioReportService.getApiScenarioId(scenaName,scenarioReport.getProjectId()); String scenarioID = apiScenarioReportService.getApiScenarioId(scenaName, scenarioReport.getProjectId());
testResult.setTestId(scenarioID); testResult.setTestId(scenarioID);
} else { } else {
apiTestService.changeStatus(testId, APITestStatus.Completed); apiTestService.changeStatus(testId, APITestStatus.Completed);
@ -224,14 +227,14 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
} }
} }
try { try {
sendTask(report,reportUrl, testResult); sendTask(report, reportUrl, testResult);
} catch (Exception e) { } catch (Exception e) {
LogUtil.error(e.getMessage(), e); LogUtil.error(e.getMessage(), e);
} }
} }
private static void sendTask(ApiTestReport report,String reportUrl, TestResult testResult) { private static void sendTask(ApiTestReport report, String reportUrl, TestResult testResult) {
SystemParameterService systemParameterService = CommonBeanFactory.getBean(SystemParameterService.class); SystemParameterService systemParameterService = CommonBeanFactory.getBean(SystemParameterService.class);
NoticeSendService noticeSendService = CommonBeanFactory.getBean(NoticeSendService.class); NoticeSendService noticeSendService = CommonBeanFactory.getBean(NoticeSendService.class);
assert systemParameterService != null; assert systemParameterService != null;
@ -239,7 +242,7 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo(); BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
String url = reportUrl; String url = reportUrl;
if(StringUtils.isEmpty(url)){ if (StringUtils.isEmpty(url)) {
url = baseSystemConfigDTO.getUrl() + "/#/api/report/view/" + report.getId(); url = baseSystemConfigDTO.getUrl() + "/#/api/report/view/" + report.getId();
} }
String successContext = ""; String successContext = "";

View File

@ -53,7 +53,7 @@
SELECT scene.`name` AS caseName,apiScene.testPlanName AS testPlan,count(report.id) AS failureTimes,'scenario' AS caseType SELECT scene.`name` AS caseName,apiScene.testPlanName AS testPlan,count(report.id) AS failureTimes,'scenario' AS caseType
FROM api_scenario_report report FROM api_scenario_report report
INNER JOIN api_scenario_report_detail reportDetail ON report.id = reportDetail.report_id 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 LEFT JOIN
( (
SELECT SELECT

View File

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

View File

@ -38,17 +38,17 @@
<select id="countTaskByProjectId" resultType="java.lang.Long"> <select id="countTaskByProjectId" resultType="java.lang.Long">
SELECT COUNT(id) AS countNumber FROM `schedule` WHERE resource_id IN ( 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 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>
<select id="countTaskByProjectIdAndCreateTimeRange" resultType="java.lang.Long"> <select id="countTaskByProjectIdAndCreateTimeRange" resultType="java.lang.Long">
SELECT COUNT(id) AS countNumber FROM `schedule` SELECT COUNT(id) AS countNumber FROM `schedule`
WHERE resource_id IN ( 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 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} AND create_time BETWEEN #{startTime} and #{endTime}
</select> </select>