Do UUID saves in batches.

This commit is contained in:
t00thpick1 2014-08-08 00:13:30 -04:00
parent f2881f02c8
commit 6ee2d7d823

View File

@ -18,6 +18,7 @@ import com.gmail.nossr50.util.uuid.UUIDFetcher;
public class UUIDUpdateAsyncTask extends BukkitRunnable { public class UUIDUpdateAsyncTask extends BukkitRunnable {
private mcMMO plugin; private mcMMO plugin;
private static final int MAX_LOOKUP = Math.max(HiddenConfig.getInstance().getUUIDConvertAmount(), 100); private static final int MAX_LOOKUP = Math.max(HiddenConfig.getInstance().getUUIDConvertAmount(), 100);
private static final int BATCH_SIZE = 5000;
private List<String> userNames; private List<String> userNames;
private int size; private int size;
@ -64,9 +65,13 @@ public class UUIDUpdateAsyncTask extends BukkitRunnable {
size = userNames.size(); size = userNames.size();
Misc.printProgress(checkedUsers, DatabaseManager.progressInterval, startMillis); Misc.printProgress(checkedUsers, DatabaseManager.progressInterval, startMillis);
if (fetchedUUIDs.size() > BATCH_SIZE) {
mcMMO.getDatabaseManager().saveUserUUIDs(fetchedUUIDs);
fetchedUUIDs = new HashMap<String, UUID>();
}
} }
if (mcMMO.getDatabaseManager().saveUserUUIDs(fetchedUUIDs)) { if (fetchedUUIDs.size() == 0 || mcMMO.getDatabaseManager().saveUserUUIDs(fetchedUUIDs)) {
mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_UUIDS); mcMMO.getUpgradeManager().setUpgradeCompleted(UpgradeType.ADD_UUIDS);
plugin.getLogger().info("UUID upgrade completed!"); plugin.getLogger().info("UUID upgrade completed!");
} }