From 93571273b180cb9ba9097b2166ce80671070ade0 Mon Sep 17 00:00:00 2001 From: T00thpick1 Date: Sun, 13 Jan 2013 23:58:50 -0500 Subject: [PATCH] Speed up purgeOldUsers task --- .../nossr50/runnables/UserPurgeTask.java | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/runnables/UserPurgeTask.java b/src/main/java/com/gmail/nossr50/runnables/UserPurgeTask.java index f8da443db..c7300f72c 100644 --- a/src/main/java/com/gmail/nossr50/runnables/UserPurgeTask.java +++ b/src/main/java/com/gmail/nossr50/runnables/UserPurgeTask.java @@ -59,25 +59,20 @@ public class UserPurgeTask implements Runnable { private void purgeOldSQL() { plugin.getLogger().info("Purging old users..."); long currentTime = System.currentTimeMillis(); - String query = "taming+mining+woodcutting+repair+unarmed+herbalism+excavation+archery+swords+axes+acrobatics+fishing"; - HashMap> userslist = database.read("SELECT " + query + ", user_id FROM " + tablePrefix + "skills WHERE " + query + " > 0 ORDER BY " + query + " DESC "); + long purgeTime = 2630000000L; + HashMap> usernames = = database.read("SELECT user FROM " + tablePrefix + "users WHERE ((" + currentTime + " - lastlogin*1000) > " + purgeTime + ")"); + database.write("DELETE FROM " + tablePrefix + "users WHERE " + tablePrefix + "users.id IN (SELECT * FROM (SELECT id FROM " + tablePrefix + "users WHERE ((" + currentTime + " - lastlogin*1000) > " + purgeTime + ")) AS p)"); int purgedUsers = 0; + for (int i = 1; i <= usernames.size(); i++) { + String playerName = usernames.get(i).get(0); - for (int i = 1; i <= userslist.size(); i++) { - int userId = Integer.valueOf(userslist.get(i).get(1)); - HashMap> username = database.read("SELECT user FROM " + tablePrefix + "users WHERE id = '" + userId + "'"); - String playerName = username.get(1).get(0); - - long lastLoginTime = database.getInt("SELECT lastlogin FROM " + tablePrefix + "users WHERE id = '" + userId + "'") * 1000L; - long loginDifference = currentTime - lastLoginTime; - - if (loginDifference > 2630000000L) { - database.write("DELETE FROM " + databaseName + "." + tablePrefix + "users WHERE " + tablePrefix + "users.id IN " + userId); - profileCleanup(playerName); - - purgedUsers++; + if (playerName == null) { + continue; } + + profileCleanup(playerName); + purgedUsers++; } plugin.getLogger().info("Purged " + purgedUsers + " users from the database.");