From 17579896f1c80ca4feccf4c96643aff43ca6e3d6 Mon Sep 17 00:00:00 2001 From: turt2live Date: Wed, 8 Jul 2015 18:04:43 -0600 Subject: [PATCH] Move UUID caching code to convert command execution. Addresses #88 Instead of loading the cache up front (potentially taking minutes) we now move the UUID caching to the command execution. Although this may increase the command execution time it does reduce the time spent starting the server and furthermore saves a little bit of memory from being used. The cache is only seeded if the UUID provider has not been initialized. If it has, then the seeding does not occur. --- .../playervaults/commands/ConvertCommand.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/drtshock/playervaults/commands/ConvertCommand.java b/src/main/java/com/drtshock/playervaults/commands/ConvertCommand.java index 667a7a0..26bd972 100644 --- a/src/main/java/com/drtshock/playervaults/commands/ConvertCommand.java +++ b/src/main/java/com/drtshock/playervaults/commands/ConvertCommand.java @@ -18,22 +18,10 @@ import java.util.*; public class ConvertCommand implements CommandExecutor { private final List converters = new ArrayList<>(); - private final ServiceProvider uuidProvider; + private ServiceProvider uuidProvider; public ConvertCommand() { converters.add(new BackpackConverter()); - - CachingServiceProvider cachedUuidProvider = new CachingServiceProvider(new ApiV2Service()); - Map seed = new HashMap<>(); - - for (OfflinePlayer player : PlayerVaults.getInstance().getServer().getOfflinePlayers()) { - if (player.hasPlayedBefore()) { - seed.put(player.getUniqueId(), player.getName()); - } - } - - cachedUuidProvider.seedLoad(seed, 6 * 60 * 60); // 6 hour cache time - uuidProvider = cachedUuidProvider; } @Override @@ -64,6 +52,20 @@ public class ConvertCommand implements CommandExecutor { PlayerVaults.getInstance().getServer().getScheduler().runTaskLaterAsynchronously(PlayerVaults.getInstance(), new Runnable() { @Override public void run() { + if (uuidProvider == null) { + CachingServiceProvider cachingUuidProvider = new CachingServiceProvider(new ApiV2Service()); + Map seed = new HashMap<>(); + + for (OfflinePlayer player : PlayerVaults.getInstance().getServer().getOfflinePlayers()) { + if (player.hasPlayedBefore()) { + seed.put(player.getUniqueId(), player.getName()); + } + } + + cachingUuidProvider.seedLoad(seed, 6 * 60 * 60); // 6 hour cache time + uuidProvider = cachingUuidProvider; + } + int converted = 0; VaultOperations.setLocked(true); for (Converter converter : applicableConverters) {