From 3c84748f9d6f0f0a20635e0e4827a1d3e15aa902 Mon Sep 17 00:00:00 2001 From: Zzm0809 <934230207@qq.com> Date: Mon, 9 Dec 2024 17:12:36 +0800 Subject: [PATCH] [Optimization] modify sqllite data position (#4032) Co-authored-by: Zzm0809 --- .../src/main/java/org/dinky/utils/SqliteUtil.java | 12 ++++++++---- .../dinky/data/constant/MonitorTableConstant.java | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/dinky-admin/src/main/java/org/dinky/utils/SqliteUtil.java b/dinky-admin/src/main/java/org/dinky/utils/SqliteUtil.java index 328aeb71d1..4dfc221efb 100644 --- a/dinky-admin/src/main/java/org/dinky/utils/SqliteUtil.java +++ b/dinky-admin/src/main/java/org/dinky/utils/SqliteUtil.java @@ -19,6 +19,9 @@ package org.dinky.utils; +import org.dinky.data.constant.DirConstant; +import org.dinky.data.constant.MonitorTableConstant; + import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; @@ -35,11 +38,12 @@ public enum SqliteUtil { INSTANCE; private Connection connection; - private final AtomicLong lastRecyle = new AtomicLong(0); + private final AtomicLong lastRecycle = new AtomicLong(0); static { try { - SqliteUtil.INSTANCE.connect("dinky.db"); + SqliteUtil.INSTANCE.connect( + DirConstant.getTempRootDir() + DirConstant.FILE_SEPARATOR + MonitorTableConstant.DINKY_DB); SqliteUtil.INSTANCE.recyleData(); } catch (SQLException e) { throw new RuntimeException(e); @@ -68,10 +72,10 @@ public void executeSql(String sql) throws SQLException { public void recyleData() { long now = System.currentTimeMillis(); - if (now - lastRecyle.get() < 1000 * 60 * 60) { + if (now - lastRecycle.get() < 1000 * 60 * 60) { return; } - lastRecyle.set(now); + lastRecycle.set(now); try { String sql = "DELETE FROM dinky_metrics WHERE heart_time <= datetime('now', '-7 days')"; executeSql(sql); diff --git a/dinky-common/src/main/java/org/dinky/data/constant/MonitorTableConstant.java b/dinky-common/src/main/java/org/dinky/data/constant/MonitorTableConstant.java index 5a5e3507e9..c46f6525ec 100644 --- a/dinky-common/src/main/java/org/dinky/data/constant/MonitorTableConstant.java +++ b/dinky-common/src/main/java/org/dinky/data/constant/MonitorTableConstant.java @@ -20,7 +20,7 @@ package org.dinky.data.constant; public final class MonitorTableConstant { - public static final String DINKY_DB = "dinky_db"; + public static final String DINKY_DB = "dinky.db"; public static final String DINKY_METRICS = "dinky_metrics"; public static final String HEART_TIME = "heart_time"; public static final String JOB_ID = "job_id";