Remove Static Abuse - Database Tasks

This commit is contained in:
nossr50
2019-07-03 00:56:25 -07:00
parent 4da455b9d2
commit 982e67af70
26 changed files with 71 additions and 45 deletions

View File

@ -8,6 +8,7 @@ import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Logger;
public interface DatabaseManager {
/**
@ -29,6 +30,19 @@ public interface DatabaseManager {
*/
public boolean removeUser(String playerName, UUID uuid);
/**
* Prints progress on long database operations
* @param convertedUsers amount of users converted so far
* @param startMillis the start time stamp in millis
* @param logger logger
*/
//TODO: Hacky fix, cleanup later
default void printProgress(int convertedUsers, long startMillis, Logger logger) {
if ((convertedUsers % getDatabaseProgressPrintInterval()) == 0) {
logger.info(String.format("Conversion progress: %d users at %.2f users/second", convertedUsers, convertedUsers / (double) ((System.currentTimeMillis() - startMillis) / 1000)));
}
}
/**
* Removes any cache used for faster lookups
* Currently only used for SQL
@ -125,6 +139,12 @@ public interface DatabaseManager {
boolean saveUserUUIDs(Map<String, UUID> fetchedUUIDs);
/**
* Gets the interval in which any task that does an operation over the whole database should print progress updates to console
* @return the interval in which progress should be reported for database wide operations
*/
int getDatabaseProgressPrintInterval();
/**
* Retrieve the type of database in use. Custom databases should return CUSTOM.
*

View File

@ -85,6 +85,11 @@ public final class FlatFileDatabaseManager implements DatabaseManager {
}*/
}
@Override
public int getDatabaseProgressPrintInterval() {
return progressInterval;
}
public void purgePowerlessUsers() {
int purgedUsers = 0;

View File

@ -23,7 +23,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
private final String COM_MYSQL_JDBC_DRIVER = "com.mysql.jdbc.Driver";
private final String ALL_QUERY_VERSION = "total";
private final Map<UUID, Integer> cachedUserIDs = new HashMap<>();
private String tablePrefix = pluginRef.getMySQLConfigSettings().getConfigSectionDatabase().getTablePrefix();
private String tablePrefix;
private DataSource miscPool;
private DataSource loadPool;
private DataSource savePool;
@ -37,6 +37,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
protected SQLDatabaseManager(mcMMO pluginRef) {
this.pluginRef = pluginRef;
tablePrefix = pluginRef.getMySQLConfigSettings().getConfigSectionDatabase().getTablePrefix();
purgeTime = 2630000000L * pluginRef.getDatabaseCleaningSettings().getOldUserCutoffMonths();
progressInterval = 200;
@ -113,6 +115,11 @@ public final class SQLDatabaseManager implements DatabaseManager {
return poolProperties;
}
@Override
public int getDatabaseProgressPrintInterval() {
return progressInterval;
}
public void purgePowerlessUsers() {
massUpdateLock.lock();
pluginRef.getLogger().info("Purging powerless users...");