Give periodic status messages to the console in conversion

This commit is contained in:
riking 2013-10-15 18:32:54 -07:00 committed by TfT_02
parent 4a428a47af
commit dbd27b641e
4 changed files with 24 additions and 0 deletions

View File

@ -11,6 +11,8 @@ import com.gmail.nossr50.datatypes.player.PlayerProfile;
public interface DatabaseManager { public interface DatabaseManager {
// One month in milliseconds // One month in milliseconds
public final long PURGE_TIME = 2630000000L * Config.getInstance().getOldUsersCutoff(); public final long PURGE_TIME = 2630000000L * Config.getInstance().getOldUsersCutoff();
// During convertUsers, how often to output a status
public final int progressInterval = 200;
/** /**
* Purge users with 0 power level from the database. * Purge users with 0 power level from the database.

View File

@ -411,6 +411,8 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
public void convertUsers(DatabaseManager destination) { public void convertUsers(DatabaseManager destination) {
BufferedReader in = null; BufferedReader in = null;
String usersFilePath = mcMMO.getUsersFilePath(); String usersFilePath = mcMMO.getUsersFilePath();
int convertedUsers = 0;
long startMillis = System.currentTimeMillis();
synchronized (fileWritingLock) { synchronized (fileWritingLock) {
try { try {
@ -427,6 +429,11 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
convertedUsers++;
if ((convertedUsers % DatabaseManager.progressInterval) == 0) {
// Can't use Bukkit.broadcastMessage because async
System.out.println(String.format("[mcMMO] Conversion progress: %d users at %.2f users/second", convertedUsers, convertedUsers / ((System.currentTimeMillis() - startMillis) / 1000D)));
}
} }
} }
catch (Exception e) { catch (Exception e) {

View File

@ -447,6 +447,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
+ "WHERE u.user = ?"); + "WHERE u.user = ?");
List<String> usernames = getStoredUsers(); List<String> usernames = getStoredUsers();
ResultSet result = null; ResultSet result = null;
int convertedUsers = 0;
long startMillis = System.currentTimeMillis();
for (String playerName : usernames) { for (String playerName : usernames) {
statement.setString(1, playerName); statement.setString(1, playerName);
try { try {
@ -458,6 +460,11 @@ public final class SQLDatabaseManager implements DatabaseManager {
catch (SQLException e) { catch (SQLException e) {
// Ignore // Ignore
} }
convertedUsers++;
if ((convertedUsers % DatabaseManager.progressInterval) == 0) {
// Can't use Bukkit.broadcastMessage because async
System.out.println(String.format("[mcMMO] Conversion progress: %d users at %.2f users/second", convertedUsers, convertedUsers / ((System.currentTimeMillis() - startMillis) / 1000D)));
}
} }
} }
catch (SQLException e) { catch (SQLException e) {

View File

@ -5,6 +5,7 @@ import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.config.experience.ExperienceConfig; import com.gmail.nossr50.config.experience.ExperienceConfig;
import com.gmail.nossr50.database.DatabaseManager;
import com.gmail.nossr50.datatypes.experience.FormulaType; import com.gmail.nossr50.datatypes.experience.FormulaType;
import com.gmail.nossr50.datatypes.player.McMMOPlayer; import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.player.PlayerProfile; import com.gmail.nossr50.datatypes.player.PlayerProfile;
@ -23,6 +24,8 @@ public class FormulaConversionTask extends BukkitRunnable {
@Override @Override
public void run() { public void run() {
int convertedUsers = 0;
long startMillis = System.currentTimeMillis();
for (String playerName : mcMMO.getDatabaseManager().getStoredUsers()) { for (String playerName : mcMMO.getDatabaseManager().getStoredUsers()) {
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName, true); McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName, true);
PlayerProfile profile; PlayerProfile profile;
@ -43,6 +46,11 @@ public class FormulaConversionTask extends BukkitRunnable {
profile = mcMMOPlayer.getProfile(); profile = mcMMOPlayer.getProfile();
editValues(profile); editValues(profile);
} }
convertedUsers++;
if ((convertedUsers % DatabaseManager.progressInterval) == 0) {
// Can't use Bukkit.broadcastMessage because async
System.out.println(String.format("[mcMMO] Conversion progress: %d users at %.2f users/second", convertedUsers, convertedUsers / ((System.currentTimeMillis() - startMillis) / 1000D)));
}
} }
mcMMO.getFormulaManager().setPreviousFormulaType(formulaType); mcMMO.getFormulaManager().setPreviousFormulaType(formulaType);