Skip to content

Commit

Permalink
[Optimization] modify sqllite data position (#4032)
Browse files Browse the repository at this point in the history
Co-authored-by: Zzm0809 <Zzm0809@users.noreply.github.com>
  • Loading branch information
Zzm0809 and Zzm0809 authored Dec 9, 2024
1 parent 97c267d commit 3c84748
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions dinky-admin/src/main/java/org/dinky/utils/SqliteUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 3c84748

Please sign in to comment.