mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
Purging shouldn't be main thread, also we have no reason to refresh profiles of purged users, as old users aren't online, and powerless users have nothing to wipe.
This commit is contained in:
parent
966de87ef9
commit
ae5347bc0f
@ -7,7 +7,6 @@ import java.sql.ResultSetMetaData;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -31,6 +30,7 @@ import snaq.db.ConnectionPool;
|
||||
|
||||
public final class SQLDatabaseManager implements DatabaseManager {
|
||||
private static final String ALL_QUERY_VERSION = "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing+alchemy";
|
||||
private static final String S_ALL_QUERY_STRING = "s.taming+s.mining+s.woodcutting+s.repair+s.unarmed+s.herbalism+s.excavation+s.archery+s.swords+s.axes+s.acrobatics+s.fishing+s.alchemy";
|
||||
private String tablePrefix = Config.getInstance().getMySQLTablePrefix();
|
||||
|
||||
private final int POOL_FETCH_TIMEOUT = 0; // How long a method will wait for a connection. Since none are on main thread, we can safely say wait for as long as you like.
|
||||
@ -80,39 +80,23 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
|
||||
Connection connection = null;
|
||||
Statement statement = null;
|
||||
ResultSet resultSet = null;
|
||||
List<String> usernames = new ArrayList<String>();
|
||||
|
||||
try {
|
||||
connection = connectionPool.getConnection(POOL_FETCH_TIMEOUT);
|
||||
statement = connection.createStatement();
|
||||
resultSet = statement.executeQuery("SELECT u.user FROM " + tablePrefix + "skills AS s, " + tablePrefix + "users AS u WHERE s.user_id = u.id AND (s.taming+s.mining+s.woodcutting+s.repair+s.unarmed+s.herbalism+s.excavation+s.archery+s.swords+s.axes+s.acrobatics+s.fishing) = 0");
|
||||
|
||||
while (resultSet.next()) {
|
||||
usernames.add(resultSet.getString("user"));
|
||||
}
|
||||
|
||||
resultSet.close();
|
||||
|
||||
statement.executeUpdate("DELETE FROM u, e, h, s, c USING " + tablePrefix + "users u " +
|
||||
"JOIN " + tablePrefix + "experience e ON (u.id = e.user_id) " +
|
||||
"JOIN " + tablePrefix + "huds h ON (u.id = h.user_id) " +
|
||||
"JOIN " + tablePrefix + "skills s ON (u.id = s.user_id) " +
|
||||
"JOIN " + tablePrefix + "cooldowns c ON (u.id = c.user_id) " +
|
||||
"WHERE (s.taming+s.mining+s.woodcutting+s.repair+s.unarmed+s.herbalism+s.excavation+s.archery+s.swords+s.axes+s.acrobatics+s.fishing) = 0");
|
||||
"WHERE (" + S_ALL_QUERY_STRING + ") = 0");
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
printErrors(ex);
|
||||
}
|
||||
finally {
|
||||
if (resultSet != null) {
|
||||
try {
|
||||
resultSet.close();
|
||||
}
|
||||
catch (SQLException e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
if (statement != null) {
|
||||
try {
|
||||
statement.close();
|
||||
@ -131,10 +115,6 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
}
|
||||
|
||||
if (!usernames.isEmpty()) {
|
||||
processPurge(usernames);
|
||||
}
|
||||
|
||||
mcMMO.p.getLogger().info("Purged " + usernames.size() + " users from the database.");
|
||||
}
|
||||
|
||||
@ -143,19 +123,11 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
|
||||
Connection connection = null;
|
||||
Statement statement = null;
|
||||
ResultSet resultSet = null;
|
||||
List<String> usernames = new ArrayList<String>();
|
||||
|
||||
try {
|
||||
connection = connectionPool.getConnection(POOL_FETCH_TIMEOUT);
|
||||
statement = connection.createStatement();
|
||||
resultSet = statement.executeQuery("SELECT user FROM " + tablePrefix + "users WHERE ((NOW() - lastlogin * " + Misc.TIME_CONVERSION_FACTOR + ") > " + PURGE_TIME + ")");
|
||||
|
||||
while (resultSet.next()) {
|
||||
usernames.add(resultSet.getString("user"));
|
||||
}
|
||||
|
||||
resultSet.close();
|
||||
|
||||
statement.executeUpdate("DELETE FROM u, e, h, s, c USING " + tablePrefix + "users u " +
|
||||
"JOIN " + tablePrefix + "experience e ON (u.id = e.user_id) " +
|
||||
@ -168,14 +140,6 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
printErrors(ex);
|
||||
}
|
||||
finally {
|
||||
if (resultSet != null) {
|
||||
try {
|
||||
resultSet.close();
|
||||
}
|
||||
catch (SQLException e) {
|
||||
// Ignore
|
||||
}
|
||||
}
|
||||
if (statement != null) {
|
||||
try {
|
||||
statement.close();
|
||||
@ -194,10 +158,6 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
}
|
||||
|
||||
if (!usernames.isEmpty()) {
|
||||
processPurge(usernames);
|
||||
}
|
||||
|
||||
mcMMO.p.getLogger().info("Purged " + usernames.size() + " users from the database.");
|
||||
}
|
||||
|
||||
@ -1237,12 +1197,6 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
}
|
||||
|
||||
private void processPurge(Collection<String> usernames) {
|
||||
for (String user : usernames) {
|
||||
Misc.profileCleanup(user);
|
||||
}
|
||||
}
|
||||
|
||||
private PlayerProfile loadFromResult(String playerName, ResultSet result) throws SQLException {
|
||||
Map<SkillType, Integer> skills = new EnumMap<SkillType, Integer>(SkillType.class); // Skill & Level
|
||||
Map<SkillType, Float> skillsXp = new EnumMap<SkillType, Float>(SkillType.class); // Skill & XP
|
||||
|
@ -469,10 +469,10 @@ public class mcMMO extends JavaPlugin {
|
||||
long purgeIntervalTicks = Config.getInstance().getPurgeInterval() * 60L * 60L * Misc.TICK_CONVERSION_FACTOR;
|
||||
|
||||
if (purgeIntervalTicks == 0) {
|
||||
new UserPurgeTask().runTaskLater(this, 2 * Misc.TICK_CONVERSION_FACTOR); // Start 2 seconds after startup.
|
||||
new UserPurgeTask().runTaskLaterAsynchronously(this, 2 * Misc.TICK_CONVERSION_FACTOR); // Start 2 seconds after startup.
|
||||
}
|
||||
else if (purgeIntervalTicks > 0) {
|
||||
new UserPurgeTask().runTaskTimer(this, purgeIntervalTicks, purgeIntervalTicks);
|
||||
new UserPurgeTask().runTaskTimerAsynchronously(this, purgeIntervalTicks, purgeIntervalTicks);
|
||||
}
|
||||
|
||||
// Automatically remove old members from parties
|
||||
|
@ -1,17 +1,22 @@
|
||||
package com.gmail.nossr50.runnables.database;
|
||||
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.Config;
|
||||
|
||||
public class UserPurgeTask extends BukkitRunnable {
|
||||
private ReentrantLock lock = new ReentrantLock();
|
||||
@Override
|
||||
public void run() {
|
||||
lock.lock();
|
||||
mcMMO.getDatabaseManager().purgePowerlessUsers();
|
||||
|
||||
if (Config.getInstance().getOldUsersCutoff() != -1) {
|
||||
mcMMO.getDatabaseManager().purgeOldUsers();
|
||||
}
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user