mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-29 08:36:45 +01:00
Give periodic status messages to the console in conversion
This commit is contained in:
parent
4a428a47af
commit
dbd27b641e
@ -11,6 +11,8 @@ import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
public interface DatabaseManager {
|
||||
// One month in milliseconds
|
||||
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.
|
||||
|
@ -411,6 +411,8 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
||||
public void convertUsers(DatabaseManager destination) {
|
||||
BufferedReader in = null;
|
||||
String usersFilePath = mcMMO.getUsersFilePath();
|
||||
int convertedUsers = 0;
|
||||
long startMillis = System.currentTimeMillis();
|
||||
|
||||
synchronized (fileWritingLock) {
|
||||
try {
|
||||
@ -427,6 +429,11 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
||||
catch (Exception e) {
|
||||
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) {
|
||||
|
@ -447,6 +447,8 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
+ "WHERE u.user = ?");
|
||||
List<String> usernames = getStoredUsers();
|
||||
ResultSet result = null;
|
||||
int convertedUsers = 0;
|
||||
long startMillis = System.currentTimeMillis();
|
||||
for (String playerName : usernames) {
|
||||
statement.setString(1, playerName);
|
||||
try {
|
||||
@ -458,6 +460,11 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
catch (SQLException e) {
|
||||
// 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) {
|
||||
|
@ -5,6 +5,7 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
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.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.player.PlayerProfile;
|
||||
@ -23,6 +24,8 @@ public class FormulaConversionTask extends BukkitRunnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
int convertedUsers = 0;
|
||||
long startMillis = System.currentTimeMillis();
|
||||
for (String playerName : mcMMO.getDatabaseManager().getStoredUsers()) {
|
||||
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(playerName, true);
|
||||
PlayerProfile profile;
|
||||
@ -43,6 +46,11 @@ public class FormulaConversionTask extends BukkitRunnable {
|
||||
profile = mcMMOPlayer.getProfile();
|
||||
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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user