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.
This commit is contained in:
@@ -18,22 +18,10 @@ import java.util.*;
|
||||
public class ConvertCommand implements CommandExecutor {
|
||||
|
||||
private final List<Converter> converters = new ArrayList<>();
|
||||
private final ServiceProvider uuidProvider;
|
||||
private ServiceProvider uuidProvider;
|
||||
|
||||
public ConvertCommand() {
|
||||
converters.add(new BackpackConverter());
|
||||
|
||||
CachingServiceProvider cachedUuidProvider = new CachingServiceProvider(new ApiV2Service());
|
||||
Map<UUID, String> 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<UUID, String> 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) {
|
||||
|
||||
Reference in New Issue
Block a user