refactor(项目设置): 定时清理接口报告优化
This commit is contained in:
parent
37cd6abf07
commit
1401b27d2e
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 < #{time}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -460,5 +460,8 @@
|
|||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
<select id="selectByProjectIdAndLessThanTime" resultType="java.lang.String">
|
||||
select id from api_scenario_report where create_time < #{time} and project_id = #{projectId}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
|
Loading…
Reference in New Issue