From 704148e47fa5e677fbd946d8f7e82f5b1209d9e3 Mon Sep 17 00:00:00 2001 From: SirYwell Date: Thu, 16 Jun 2022 14:49:52 +0200 Subject: [PATCH] avoid quadratic overhead for UUID collection --- .../plotsquared/bukkit/BukkitPlatform.java | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java index d2da2fb2a..f249c1b5f 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java @@ -656,20 +656,15 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl final @NonNull SQLiteUUIDService sqLiteUUIDService, final @NonNull CacheUUIDService cacheUUIDService ) { - // Load all uuids into a big chunky boi queue - final Queue uuidQueue = new LinkedBlockingQueue<>(); + // Record all unique UUID's and put them into a queue + final Set uuidSet = new HashSet<>(); PlotSquared.get().forEachPlotRaw(plot -> { - final Set uuids = new HashSet<>(); - uuids.add(plot.getOwnerAbs()); - uuids.addAll(plot.getMembers()); - uuids.addAll(plot.getTrusted()); - uuids.addAll(plot.getDenied()); - for (final UUID uuid : uuids) { - if (!uuidQueue.contains(uuid)) { - uuidQueue.add(uuid); - } - } + uuidSet.add(plot.getOwnerAbs()); + uuidSet.addAll(plot.getMembers()); + uuidSet.addAll(plot.getTrusted()); + uuidSet.addAll(plot.getDenied()); }); + final Queue uuidQueue = new LinkedBlockingQueue<>(uuidSet); LOGGER.info("(UUID) {} UUIDs will be cached", uuidQueue.size());