mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-11-12 21:54:02 +01:00
Only set the status every 5% -> Performance Improvement of 17s; previous: 20s, now: 4s.
This commit is contained in:
parent
52cec5912b
commit
dedb95766a
@ -18,6 +18,7 @@ import java.util.*;
|
|||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Abstract class used for importing data from other plugins.
|
* Abstract class used for importing data from other plugins.
|
||||||
@ -81,7 +82,9 @@ public abstract class Importer {
|
|||||||
List<UUID> unSaved = new ArrayList<>(uuids);
|
List<UUID> unSaved = new ArrayList<>(uuids);
|
||||||
unSaved.removeAll(saved);
|
unSaved.removeAll(saved);
|
||||||
|
|
||||||
String createUserObjects = "Creating new UserData objects for: " + unSaved.size();
|
int amount = unSaved.size();
|
||||||
|
|
||||||
|
String createUserObjects = "Creating " + amount + " new UserData objects";
|
||||||
processStatus.setStatus(processName, createUserObjects);
|
processStatus.setStatus(processName, createUserObjects);
|
||||||
|
|
||||||
Map<UUID, IOfflinePlayer> offlinePlayers = Fetch.getIOfflinePlayers().stream().collect(Collectors.toMap(IOfflinePlayer::getUuid, Function.identity()));
|
Map<UUID, IOfflinePlayer> offlinePlayers = Fetch.getIOfflinePlayers().stream().collect(Collectors.toMap(IOfflinePlayer::getUuid, Function.identity()));
|
||||||
@ -95,14 +98,23 @@ public abstract class Importer {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
AtomicInteger currentUser = new AtomicInteger(0);
|
AtomicInteger currentUser = new AtomicInteger(0);
|
||||||
int amount = unSaved.size();
|
AtomicInteger currentPercent = new AtomicInteger(0);
|
||||||
|
|
||||||
|
int fivePercent = amount / 20;
|
||||||
|
|
||||||
|
//Using Set because of better Collection#contains() performance
|
||||||
|
Set<Integer> milestones = IntStream.rangeClosed(1, 20)
|
||||||
|
.mapToObj(i -> i * fivePercent)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
offlineP.parallelStream()
|
offlineP.parallelStream()
|
||||||
.map(NewPlayerCreator::createNewOfflinePlayer)
|
.map(NewPlayerCreator::createNewOfflinePlayer)
|
||||||
.forEach(newPlayer -> {
|
.forEach(newPlayer -> {
|
||||||
newPlayer.setLastPlayed(newPlayer.getRegistered());
|
newPlayer.setLastPlayed(newPlayer.getRegistered());
|
||||||
newUsers.add(newPlayer);
|
newUsers.add(newPlayer);
|
||||||
processStatus.setStatus(processName, "Creating new UserData objects: " + currentUser.addAndGet(1) + "/" + amount);
|
if (milestones.contains(currentUser.incrementAndGet())) {
|
||||||
|
processStatus.setStatus(processName, "Creating new UserData objects: " + currentPercent.addAndGet(5) + "%");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Benchmark.stop(createUserObjects);
|
Benchmark.stop(createUserObjects);
|
||||||
|
Loading…
Reference in New Issue
Block a user