Make the purge progress run more balanced (Fixes #696)

This commit is contained in:
games647
2016-05-09 13:09:40 +02:00
parent b728b297b8
commit 0bd6ac5cc8
10 changed files with 255 additions and 115 deletions
@@ -15,6 +15,7 @@ import fr.xephi.authme.security.crypts.HashedPassword;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
@@ -137,11 +138,12 @@ public class CacheDataSource implements DataSource {
}
@Override
public List<String> autoPurgeDatabase(long until) {
List<String> cleared = source.autoPurgeDatabase(until);
public Set<String> autoPurgeDatabase(long until) {
Set<String> cleared = source.autoPurgeDatabase(until);
for (String name : cleared) {
cachedAuths.invalidate(name);
}
return cleared;
}
@@ -187,7 +189,7 @@ public class CacheDataSource implements DataSource {
}
@Override
public synchronized void purgeBanned(final List<String> banned) {
public synchronized void purgeBanned(final Set<String> banned) {
source.purgeBanned(banned);
cachedAuths.invalidateAll(banned);
}
@@ -4,6 +4,7 @@ import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.security.crypts.HashedPassword;
import java.util.List;
import java.util.Set;
/**
* Interface for manipulating {@link PlayerAuth} objects from a data source.
@@ -74,7 +75,7 @@ public interface DataSource {
* @param until The minimum last login
* @return The account names that have been removed
*/
List<String> autoPurgeDatabase(long until);
Set<String> autoPurgeDatabase(long until);
/**
* Remove a user record from the database.
@@ -126,7 +127,7 @@ public interface DataSource {
*
* @param banned the list of players to delete
*/
void purgeBanned(List<String> banned);
void purgeBanned(Set<String> banned);
/**
* Return the data source type.
@@ -17,7 +17,9 @@ import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Deprecated flat file datasource. The only method guaranteed to work is {@link FlatFile#getAllAuths()}
@@ -227,11 +229,11 @@ public class FlatFile implements DataSource {
}
@Override
public List<String> autoPurgeDatabase(long until) {
public Set<String> autoPurgeDatabase(long until) {
BufferedReader br = null;
BufferedWriter bw = null;
ArrayList<String> lines = new ArrayList<>();
List<String> cleared = new ArrayList<>();
Set<String> cleared = new HashSet<>();
try {
br = new BufferedReader(new FileReader(source));
String line;
@@ -256,6 +258,7 @@ public class FlatFile implements DataSource {
silentClose(br);
silentClose(bw);
}
return cleared;
}
@@ -414,7 +417,7 @@ public class FlatFile implements DataSource {
}
@Override
public void purgeBanned(List<String> banned) {
public void purgeBanned(Set<String> banned) {
BufferedReader br = null;
BufferedWriter bw = null;
ArrayList<String> lines = new ArrayList<>();
@@ -24,7 +24,9 @@ import java.sql.SQLException;
import java.sql.Statement;
import java.sql.Types;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
*/
@@ -610,8 +612,8 @@ public class MySQL implements DataSource {
}
@Override
public synchronized List<String> autoPurgeDatabase(long until) {
List<String> list = new ArrayList<>();
public synchronized Set<String> autoPurgeDatabase(long until) {
Set<String> list = new HashSet<>();
String select = "SELECT " + col.NAME + " FROM " + tableName + " WHERE " + col.LAST_LOGIN + "<?;";
String delete = "DELETE FROM " + tableName + " WHERE " + col.LAST_LOGIN + "<?;";
try (Connection con = getConnection();
@@ -628,6 +630,7 @@ public class MySQL implements DataSource {
} catch (SQLException ex) {
logSqlException(ex);
}
return list;
}
@@ -738,7 +741,7 @@ public class MySQL implements DataSource {
}
@Override
public synchronized void purgeBanned(List<String> banned) {
public synchronized void purgeBanned(Set<String> banned) {
String sql = "DELETE FROM " + tableName + " WHERE " + col.NAME + "=?;";
try (Connection con = getConnection(); PreparedStatement pst = con.prepareStatement(sql)) {
for (String name : banned) {
@@ -16,7 +16,9 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
*/
@@ -285,8 +287,8 @@ public class SQLite implements DataSource {
}
@Override
public List<String> autoPurgeDatabase(long until) {
List<String> list = new ArrayList<>();
public Set<String> autoPurgeDatabase(long until) {
Set<String> list = new HashSet<>();
String select = "SELECT " + col.NAME + " FROM " + tableName + " WHERE " + col.LAST_LOGIN + "<?;";
String delete = "DELETE FROM " + tableName + " WHERE " + col.LAST_LOGIN + "<?;";
try (PreparedStatement selectPst = con.prepareStatement(select);
@@ -302,6 +304,7 @@ public class SQLite implements DataSource {
} catch (SQLException ex) {
logSqlException(ex);
}
return list;
}
@@ -425,7 +428,7 @@ public class SQLite implements DataSource {
}
@Override
public void purgeBanned(List<String> banned) {
public void purgeBanned(Set<String> banned) {
String sql = "DELETE FROM " + tableName + " WHERE " + col.NAME + "=?;";
try (PreparedStatement pst = con.prepareStatement(sql)) {
for (String name : banned) {