Skip to content

Commit

Permalink
Improve indexing performance
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Nov 1, 2022
1 parent 141c17c commit 4907de4
Showing 1 changed file with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ private void connectPlayer(QueueType type) {
continue;
}

indexPositionTime();
indexPositionTime(type);

Map<Integer, Instant> cache = type.getPositionCache().get(entry.getKey());
if (cache != null) {
Expand Down Expand Up @@ -313,19 +313,17 @@ private void sendXPSoundToQueueType(QueueType type) {
server.sendPluginMessage("piston:queue", out.toByteArray()));
}

private void indexPositionTime() {
for (QueueType type : Config.QUEUE_TYPES) {
int position = 0;
private void indexPositionTime(QueueType type) {
int position = 0;

for (UUID uuid : new LinkedHashMap<>(type.getQueueMap()).keySet()) {
position++;
Map<Integer, Instant> list = type.getPositionCache().get(uuid);
if (list == null) {
type.getPositionCache().put(uuid, new HashMap<>(Collections.singletonMap(position, Instant.now())));
} else {
if (!list.containsKey(position)) {
list.put(position, Instant.now());
}
for (UUID uuid : new LinkedHashMap<>(type.getQueueMap()).keySet()) {
position++;
Map<Integer, Instant> list = type.getPositionCache().get(uuid);
if (list == null) {
type.getPositionCache().put(uuid, new HashMap<>(Collections.singletonMap(position, Instant.now())));
} else {
if (!list.containsKey(position)) {
list.put(position, Instant.now());
}
}
}
Expand Down

0 comments on commit 4907de4

Please sign in to comment.