refactor(项目设置): 定时清理接口报告优化

This commit is contained in:
shiziyuan9527 2022-07-11 11:30:43 +08:00 committed by f2c-ci-robot[bot]
parent 37cd6abf07
commit 1401b27d2e
5 changed files with 12 additions and 12 deletions

View File

@ -749,7 +749,7 @@ public class ApiScenarioReportService {
reportRequest.setIds(myList);
//为预防数量太多调用删除方法时引起SQL过长的Bug此处采取分批执行的方式
//每次处理的数据数量
int handleCount = 7000;
int handleCount = 5000;
//每次处理的集合
while (ids.size() > handleCount) {
List<String> handleIdList = new ArrayList<>(handleCount);
@ -934,16 +934,8 @@ public class ApiScenarioReportService {
}
public void cleanUpReport(long time, String projectId) {
ApiScenarioReportExample example = new ApiScenarioReportExample();
example.createCriteria().andCreateTimeLessThan(time).andProjectIdEqualTo(projectId);
List<ApiScenarioReport> apiScenarioReports = apiScenarioReportMapper.selectByExample(example);
List<String> ids = apiScenarioReports.stream().map(ApiScenarioReport::getId).collect(Collectors.toList());
ApiDefinitionExecResultExample definitionExecResultExample = new ApiDefinitionExecResultExample();
definitionExecResultExample.createCriteria().andCreateTimeLessThan(time).andProjectIdEqualTo(projectId);
List<ApiDefinitionExecResult> apiDefinitionExecResults = definitionExecResultMapper.selectByExample(definitionExecResultExample);
List<String> definitionExecIds = apiDefinitionExecResults.stream().map(ApiDefinitionExecResult::getId).collect(Collectors.toList());
List<String> ids = extApiScenarioReportMapper.selectByProjectIdAndLessThanTime(projectId, time);
List<String> definitionExecIds = extApiDefinitionExecResultMapper.selectByProjectIdAndLessThanTime(projectId, time);
ids.addAll(definitionExecIds);
if (CollectionUtils.isNotEmpty(ids)) {
APIReportBatchRequest request = new APIReportBatchRequest();

View File

@ -54,4 +54,6 @@ public interface ExtApiDefinitionExecResultMapper {
String selectResourceId(String id);
List<ApiDefinitionExecResultWithBLOBs> selectRerunResult(@Param("reportId") String reportId);
List<String> selectByProjectIdAndLessThanTime(@Param("projectId") String projectId, @Param("time") long time);
}

View File

@ -443,5 +443,8 @@
ORDER BY
r.create_time ASC
</select>
<select id="selectByProjectIdAndLessThanTime" resultType="java.lang.String">
select id from api_definition_exec_result where project_id = #{projectId} and create_time &lt; #{time}
</select>
</mapper>

View File

@ -47,5 +47,5 @@ public interface ExtApiScenarioReportMapper {
List<ApiScenarioReport> findByProjectIds(@Param("request") TaskCenterRequest request);
List<String> selectByProjectIdAndLessThanTime(@Param("projectId") String projectId, @Param("time") long time);
}

View File

@ -460,5 +460,8 @@
#{id}
</foreach>
</select>
<select id="selectByProjectIdAndLessThanTime" resultType="java.lang.String">
select id from api_scenario_report where create_time &lt; #{time} and project_id = #{projectId}
</select>
</mapper>