fix: 优化查询数据表最新更新时间
Some checks are pending
Typos Check / Spell Check with Typos (push) Waiting to run

This commit is contained in:
taojinlong 2024-12-10 18:23:39 +08:00
parent 11f628bb75
commit 709c4823e1
3 changed files with 20 additions and 0 deletions

View File

@ -57,6 +57,7 @@ public class DatasourceTaskServer {
queryWrapper.eq("ds_id", dsId);
queryWrapper.eq("table_name", tableName);
queryWrapper.orderByDesc("start_time");
queryWrapper.last("limit 1");
List<CoreDatasourceTaskLog> logs = coreDatasourceTaskLogMapper.selectList(queryWrapper);
if (!CollectionUtils.isEmpty(logs)) {
return logs.get(0);
@ -192,6 +193,14 @@ public class DatasourceTaskServer {
datasourceTaskMapper.update(record, updateTaskWrapper);
}
public void cleanLog() {
long expTime = Long.parseLong("30") * 24L * 3600L * 1000L;
long threshold = System.currentTimeMillis() - expTime;
QueryWrapper<CoreDatasourceTaskLog> queryWrapper = new QueryWrapper<>();
queryWrapper.lt("start_time", threshold);
coreDatasourceTaskLogMapper.delete(queryWrapper);
}
public enum ScheduleType {
CRON, RIGHTNOW, SIMPLE_CRON, MANUAL

View File

@ -1,5 +1,6 @@
package io.dataease.job.schedule;
import io.dataease.datasource.server.DatasourceTaskServer;
import io.dataease.exportCenter.manage.ExportCenterManage;
import io.dataease.utils.LogUtil;
import jakarta.annotation.Resource;
@ -11,6 +12,8 @@ public class CleanScheduler {
@Resource(name = "exportCenterManage")
private ExportCenterManage exportCenterManage;
@Resource(name = "datasourceTaskServer")
private DatasourceTaskServer datasourceTaskServer;
@Scheduled(cron = "0 0 0 * * ?")
public void clean() {
@ -18,4 +21,11 @@ public class CleanScheduler {
exportCenterManage.cleanLog();
LogUtil.info("Execute export file cleaner success");
}
@Scheduled(cron = "0 0 0 * * ?")
public void cleanSyncLog() {
LogUtil.info("Start to clean sync log ...");
datasourceTaskServer.cleanLog();
LogUtil.info("End to clean sync log.");
}
}

View File

@ -0,0 +1 @@
CREATE INDEX idx_dataset_table_task_log_A ON core_datasource_task_log(ds_id, table_name, start_time);