Added settings for removal of TPS and Ping data.

This commit is contained in:
Rsl1122 2019-04-30 10:22:18 +03:00
parent 809e821b13
commit 0b3dad1d40
5 changed files with 28 additions and 10 deletions

View File

@ -23,7 +23,6 @@ import com.djrapitops.plan.db.access.queries.objects.TPSQueries;
import com.djrapitops.plan.db.access.transactions.Transaction;
import com.djrapitops.plan.db.sql.tables.PingTable;
import com.djrapitops.plan.db.sql.tables.TPSTable;
import com.djrapitops.plugin.api.TimeAmount;
import java.sql.PreparedStatement;
import java.sql.SQLException;
@ -38,11 +37,17 @@ import java.util.UUID;
public class RemoveOldSampledDataTransaction extends Transaction {
private final UUID serverUUID;
private final long deleteTPSOlderThanMs;
private final long deletePingOlderThanMs;
public RemoveOldSampledDataTransaction(
UUID serverUUID
UUID serverUUID,
long deleteTPSOlderThanMs,
long deletePingOlderThanMs
) {
this.serverUUID = serverUUID;
this.deleteTPSOlderThanMs = deleteTPSOlderThanMs;
this.deletePingOlderThanMs = deletePingOlderThanMs;
}
@Override
@ -61,9 +66,7 @@ public class RemoveOldSampledDataTransaction extends Transaction {
return new ExecStatement(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
// More than 3 Months ago.
long threeMonths = TimeAmount.MONTH.toMillis(3L);
statement.setLong(1, System.currentTimeMillis() - threeMonths);
statement.setLong(1, System.currentTimeMillis() - deleteTPSOlderThanMs);
statement.setInt(2, allTimePlayerPeak);
}
};
@ -77,8 +80,7 @@ public class RemoveOldSampledDataTransaction extends Transaction {
return new ExecStatement(sql) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
long twoWeeks = TimeAmount.WEEK.toMillis(2L);
statement.setLong(1, System.currentTimeMillis() - twoWeeks);
statement.setLong(1, System.currentTimeMillis() - deletePingOlderThanMs);
}
};
}

View File

@ -85,7 +85,11 @@ public class DBCleanTask extends AbsRunnable {
Database database = dbSystem.getDatabase();
try {
if (database.getState() != Database.State.CLOSED) {
database.executeTransaction(new RemoveOldSampledDataTransaction(serverInfo.getServerUUID()));
database.executeTransaction(new RemoveOldSampledDataTransaction(
serverInfo.getServerUUID(),
config.get(TimeSettings.DELETE_TPS_DATA_AFTER),
config.get(TimeSettings.DELETE_PING_DATA_AFTER)
));
database.executeTransaction(new RemoveDuplicateUserInfoTransaction());
database.executeTransaction(new RemoveUnsatisfiedConditionalPlayerResultsTransaction());
database.executeTransaction(new RemoveUnsatisfiedConditionalServerResultsTransaction());
@ -103,7 +107,7 @@ public class DBCleanTask extends AbsRunnable {
@VisibleForTesting
public int cleanOldPlayers(Database database) {
long now = System.currentTimeMillis();
long keepActiveAfter = now - config.get(TimeSettings.KEEP_INACTIVE_PLAYERS);
long keepActiveAfter = now - config.get(TimeSettings.DELETE_INACTIVE_PLAYERS_AFTER);
List<UUID> inactivePlayers = database.query(fetchInactivePlayerUUIDs(keepActiveAfter));
for (UUID uuid : inactivePlayers) {

View File

@ -35,7 +35,9 @@ public class TimeSettings {
public static final Setting<Long> AFK_THRESHOLD = new TimeSetting("Time.Thresholds.AFK_threshold");
public static final Setting<Integer> ACTIVE_LOGIN_THRESHOLD = new IntegerSetting("Time.Thresholds.Activity_index.Login_threshold", Setting::timeValidator);
public static final Setting<Long> ACTIVE_PLAY_THRESHOLD = new TimeSetting("Time.Thresholds.Activity_index.Playtime_threshold");
public static final Setting<Long> KEEP_INACTIVE_PLAYERS = new TimeSetting("Time.Thresholds.Remove_inactive_player_data_after");
public static final Setting<Long> DELETE_INACTIVE_PLAYERS_AFTER = new TimeSetting("Time.Thresholds.Remove_inactive_player_data_after");
public static final Setting<Long> DELETE_TPS_DATA_AFTER = new TimeSetting("Time.Thresholds.Remove_time_series_data_after");
public static final Setting<Long> DELETE_PING_DATA_AFTER = new TimeSetting("Time.Thresholds.Remove_ping_data_after");
public static final Setting<Long> ANALYSIS_REFRESH_PERIOD = new TimeSetting("Time.Periodic_tasks.Analysis_refresh_every");
public static final Setting<Long> EXTENSION_DATA_REFRESH_PERIOD = new TimeSetting("Time.Periodic_tasks.Extension_data_refresh_every");
public static final Setting<Long> CLEAN_CACHE_PERIOD = new TimeSetting("Time.Periodic_tasks.Clean_caches_every");

View File

@ -85,6 +85,11 @@ Time:
Unit: MINUTES
Remove_inactive_player_data_after: 180
Unit: DAYS
# Includes players online, tps and performance time series
Remove_time_series_data_after: 90
Unit: DAYS
Remove_ping_data_after: 14
Unit: DAYS
Periodic_tasks:
Extension_data_refresh_every: 1
Unit: HOURS

View File

@ -90,6 +90,11 @@ Time:
Unit: MINUTES
Remove_inactive_player_data_after: 180
Unit: DAYS
# Includes players online, tps and performance time series
Remove_time_series_data_after: 90
Unit: DAYS
Remove_ping_data_after: 14
Unit: DAYS
Periodic_tasks:
Analysis_refresh_every: 60
Unit: MINUTES