Merge pull request #492 from t00thpick1/master

Speed up powerless sql users purge
This commit is contained in:
GJ 2013-01-13 13:20:50 -08:00
commit 1f660c8c5b
2 changed files with 5 additions and 50 deletions

View File

@ -8,6 +8,8 @@ Key:
- Removal - Removal
Version 1.3.13-dev Version 1.3.13-dev
+ Overall SQL query improvements
+ Reduced number of SQL queries for mcTop command from 11 to 1, speeding it up immensely
+ Added task to prune old and powerless users from the SQL database. + Added task to prune old and powerless users from the SQL database.
*** WARNING: THIS WILL RUN AUTOMATICALLY ON YOUR DB. IF YOU ARE WORRIED *** *** WARNING: THIS WILL RUN AUTOMATICALLY ON YOUR DB. IF YOU ARE WORRIED ***
*** ABOUT DATA LOSS, BACK UP YOUR SQL DATA BEFORE INSTALLING THIS BUILD *** *** ABOUT DATA LOSS, BACK UP YOUR SQL DATA BEFORE INSTALLING THIS BUILD ***

View File

@ -28,7 +28,7 @@ public class UserPurgeTask implements Runnable {
@Override @Override
public void run() { public void run() {
if (Config.getInstance().getUseMySQL()) { if (Config.getInstance().getUseMySQL()) {
purgePowerlessSQLFaster(); purgePowerlessSQL();
purgeOldSQL(); purgeOldSQL();
} }
else { else {
@ -38,55 +38,8 @@ public class UserPurgeTask implements Runnable {
private void purgePowerlessSQL() { private void purgePowerlessSQL() {
plugin.getLogger().info("Purging powerless users..."); plugin.getLogger().info("Purging powerless users...");
String query = "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing"; HashMap<Integer, ArrayList<String>> usernames = database.read("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");
HashMap<Integer, ArrayList<String>> userslist = database.read("SELECT " + query + ", user_id FROM " + tablePrefix + "skills WHERE " + query + " = 0 ORDER BY " + query + " DESC "); database.write("DELETE FROM " + tablePrefix + "users WHERE " + tablePrefix + "users.id IN (SELECT * FROM (SELECT u.id 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) AS p)");
int purgedUsers = 0;
for (int i = 1; i <= userslist.size(); i++) {
int userId = Integer.valueOf(userslist.get(i).get(1));
HashMap<Integer, ArrayList<String>> username = database.read("SELECT user FROM " + tablePrefix + "users WHERE id = '" + userId + "'");
if (username == null) {
continue;
}
String playerName = username.get(1).get(0);
if (Bukkit.getOfflinePlayer(playerName).isOnline()) {
continue;
}
database.write("DELETE FROM " + databaseName + "." + tablePrefix + "users WHERE " + tablePrefix + "users.id IN " + userId);
profileCleanup(playerName);
purgedUsers++;
}
plugin.getLogger().info("Purged " + purgedUsers + " users from the database.");
}
private void purgePowerlessSQLFaster() {
plugin.getLogger().info("Purging powerless users...");
String query = "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing";
HashMap<Integer, ArrayList<String>> userslist = database.read("SELECT " + query + ", user_id FROM " + tablePrefix + "skills WHERE " + query + " = 0 ORDER BY " + query + " DESC ");
int purgedUsers = 0;
String userIdString = "(";
for (int i = 1; i <= userslist.size(); i++) {
int userId = Integer.valueOf(userslist.get(i).get(1));
if (i == userslist.size()) {
userIdString = userIdString + userId + ")";
}
else {
userIdString = userIdString + userId + ",";
}
}
HashMap<Integer, ArrayList<String>> usernames = database.read("SELECT user FROM " + tablePrefix + "users WHERE id IN " + userIdString);
database.write("DELETE FROM " + databaseName + "." + tablePrefix + "users WHERE " + tablePrefix + "users.id IN " + userIdString);
for (int i = 1; i <= usernames.size(); i++) { for (int i = 1; i <= usernames.size(); i++) {
String playerName = usernames.get(i).get(0); String playerName = usernames.get(i).get(0);