mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-23 19:16:37 +01:00
Improve sync task performance
This commit is contained in:
parent
6a256d59f5
commit
a1c91b9007
@ -44,10 +44,12 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Bootstrap plugin for LuckPerms running on Bukkit.
|
||||
@ -254,13 +256,23 @@ public class LPBukkitBootstrap extends JavaPlugin implements LuckPermsBootstrap
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getPlayerList() {
|
||||
return getServer().getOnlinePlayers().stream().map(Player::getName);
|
||||
public Collection<String> getPlayerList() {
|
||||
Collection<? extends Player> players = getServer().getOnlinePlayers();
|
||||
List<String> list = new ArrayList<>(players.size());
|
||||
for (Player player : players) {
|
||||
list.add(player.getName());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<UUID> getOnlinePlayers() {
|
||||
return getServer().getOnlinePlayers().stream().map(Player::getUniqueId);
|
||||
public Collection<UUID> getOnlinePlayers() {
|
||||
Collection<? extends Player> players = getServer().getOnlinePlayers();
|
||||
List<UUID> list = new ArrayList<>(players.size());
|
||||
for (Player player : players) {
|
||||
list.add(player.getUniqueId());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -43,10 +43,12 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Bootstrap plugin for LuckPerms running on BungeeCord.
|
||||
@ -249,13 +251,23 @@ public class LPBungeeBootstrap extends Plugin implements LuckPermsBootstrap {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getPlayerList() {
|
||||
return getProxy().getPlayers().stream().map(ProxiedPlayer::getName);
|
||||
public Collection<String> getPlayerList() {
|
||||
Collection<ProxiedPlayer> players = getProxy().getPlayers();
|
||||
List<String> list = new ArrayList<>(players.size());
|
||||
for (ProxiedPlayer player : players) {
|
||||
list.add(player.getName());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<UUID> getOnlinePlayers() {
|
||||
return getProxy().getPlayers().stream().map(ProxiedPlayer::getUniqueId);
|
||||
public Collection<UUID> getOnlinePlayers() {
|
||||
Collection<ProxiedPlayer> players = getProxy().getPlayers();
|
||||
List<UUID> list = new ArrayList<>(players.size());
|
||||
for (ProxiedPlayer player : players) {
|
||||
list.add(player.getUniqueId());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -78,7 +78,7 @@ public class CheckCommand extends SingleCommand {
|
||||
@Override
|
||||
public List<String> tabComplete(LuckPermsPlugin plugin, Sender sender, List<String> args) {
|
||||
return TabCompleter.create()
|
||||
.at(0, CompletionSupplier.startsWith(() -> plugin.getBootstrap().getPlayerList()))
|
||||
.at(0, CompletionSupplier.startsWith(() -> plugin.getBootstrap().getPlayerList().stream()))
|
||||
.at(1, TabCompletions.permissions(plugin))
|
||||
.complete(args);
|
||||
}
|
||||
|
@ -49,11 +49,11 @@ import me.lucko.luckperms.common.storage.misc.DataConstraints;
|
||||
import me.lucko.luckperms.common.util.CaffeineFactory;
|
||||
import me.lucko.luckperms.common.util.Uuids;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class UserParentCommand extends ParentCommand<User, UserIdentifier> {
|
||||
|
||||
@ -144,6 +144,6 @@ public class UserParentCommand extends ParentCommand<User, UserIdentifier> {
|
||||
|
||||
@Override
|
||||
protected List<String> getTargets(LuckPermsPlugin plugin) {
|
||||
return plugin.getBootstrap().getPlayerList().collect(Collectors.toList());
|
||||
return new ArrayList<>(plugin.getBootstrap().getPlayerList());
|
||||
}
|
||||
}
|
@ -34,20 +34,18 @@ import me.lucko.luckperms.common.model.manager.AbstractManager;
|
||||
import me.lucko.luckperms.common.model.manager.group.GroupManager;
|
||||
import me.lucko.luckperms.common.node.types.Inheritance;
|
||||
import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
|
||||
import me.lucko.luckperms.common.util.Iterators;
|
||||
import me.lucko.luckperms.common.verbose.event.MetaCheckEvent;
|
||||
|
||||
import net.luckperms.api.model.data.DataType;
|
||||
import net.luckperms.api.node.Node;
|
||||
import net.luckperms.api.node.types.InheritanceNode;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public abstract class AbstractUserManager<T extends User> extends AbstractManager<UUID, User, T> implements UserManager<T> {
|
||||
|
||||
@ -137,16 +135,14 @@ public abstract class AbstractUserManager<T extends User> extends AbstractManage
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> loadAllUsers() {
|
||||
Set<UUID> ids = Stream.concat(
|
||||
getAll().keySet().stream(),
|
||||
this.plugin.getBootstrap().getOnlinePlayers()
|
||||
).collect(Collectors.toSet());
|
||||
Set<UUID> ids = new HashSet<>(getAll().keySet());
|
||||
ids.addAll(this.plugin.getBootstrap().getOnlinePlayers());
|
||||
|
||||
return CompletableFuture.runAsync(() -> {
|
||||
Iterators.tryIterate(ids, id -> {
|
||||
this.plugin.getStorage().loadUser(id, null).join();
|
||||
});
|
||||
}, this.plugin.getBootstrap().getScheduler().async());
|
||||
CompletableFuture<?>[] loadTasks = ids.stream()
|
||||
.map(id -> this.plugin.getStorage().loadUser(id, null))
|
||||
.toArray(CompletableFuture[]::new);
|
||||
|
||||
return CompletableFuture.allOf(loadTasks);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -36,12 +36,12 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Instant;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Bootstrap plugin interface
|
||||
@ -197,14 +197,14 @@ public interface LuckPermsBootstrap {
|
||||
*
|
||||
* @return a {@link List} of usernames
|
||||
*/
|
||||
Stream<String> getPlayerList();
|
||||
Collection<String> getPlayerList();
|
||||
|
||||
/**
|
||||
* Gets the UUIDs of the users online on the platform
|
||||
*
|
||||
* @return a {@link Set} of UUIDs
|
||||
*/
|
||||
Stream<UUID> getOnlinePlayers();
|
||||
Collection<UUID> getOnlinePlayers();
|
||||
|
||||
/**
|
||||
* Checks if a user is online
|
||||
|
@ -43,7 +43,6 @@ import me.lucko.luckperms.common.storage.implementation.StorageImplementation;
|
||||
import me.lucko.luckperms.common.storage.implementation.sql.connection.ConnectionFactory;
|
||||
import me.lucko.luckperms.common.storage.misc.NodeEntry;
|
||||
import me.lucko.luckperms.common.storage.misc.PlayerSaveResultImpl;
|
||||
import me.lucko.luckperms.common.util.Iterators;
|
||||
import me.lucko.luckperms.common.util.gson.GsonProvider;
|
||||
|
||||
import net.luckperms.api.actionlog.Action;
|
||||
@ -584,10 +583,17 @@ public class SqlStorage implements StorageImplementation {
|
||||
Set<String> tracks;
|
||||
try (Connection c = this.connectionFactory.getConnection()) {
|
||||
tracks = selectTracks(c);
|
||||
}
|
||||
|
||||
if (!Iterators.tryIterate(tracks, this::loadTrack)) {
|
||||
throw new RuntimeException("Exception occurred whilst loading a track");
|
||||
for (String trackName : tracks) {
|
||||
Track track = this.plugin.getTrackManager().getOrMake(trackName);
|
||||
track.getIoLock().lock();
|
||||
try {
|
||||
List<String> groups = selectTrack(c, trackName);
|
||||
track.setGroups(groups);
|
||||
} finally {
|
||||
track.getIoLock().unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.plugin.getTrackManager().retainAll(tracks);
|
||||
|
@ -38,10 +38,12 @@ import cn.nukkit.plugin.PluginBase;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Bootstrap plugin for LuckPerms running on Nukkit.
|
||||
@ -201,13 +203,18 @@ public class LPNukkitBootstrap extends PluginBase implements LuckPermsBootstrap
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getPlayerList() {
|
||||
return getServer().getOnlinePlayers().values().stream().map(Player::getName);
|
||||
public Collection<String> getPlayerList() {
|
||||
Collection<Player> players = getServer().getOnlinePlayers().values();
|
||||
List<String> list = new ArrayList<>(players.size());
|
||||
for (Player player : players) {
|
||||
list.add(player.getName());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<UUID> getOnlinePlayers() {
|
||||
return getServer().getOnlinePlayers().values().stream().map(Player::getUniqueId);
|
||||
public Collection<UUID> getOnlinePlayers() {
|
||||
return new ArrayList<>(getServer().getOnlinePlayers().keySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -59,10 +59,13 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Bootstrap plugin for LuckPerms running on Sponge.
|
||||
@ -297,13 +300,27 @@ public class LPSpongeBootstrap implements LuckPermsBootstrap {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getPlayerList() {
|
||||
return getServer().map(server -> server.getOnlinePlayers().stream().map(Player::getName)).orElseGet(Stream::empty);
|
||||
public Collection<String> getPlayerList() {
|
||||
return getServer().map(server -> {
|
||||
Collection<Player> players = server.getOnlinePlayers();
|
||||
List<String> list = new ArrayList<>(players.size());
|
||||
for (Player player : players) {
|
||||
list.add(player.getName());
|
||||
}
|
||||
return list;
|
||||
}).orElse(Collections.emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<UUID> getOnlinePlayers() {
|
||||
return getServer().map(server -> server.getOnlinePlayers().stream().map(Player::getUniqueId)).orElseGet(Stream::empty);
|
||||
public Collection<UUID> getOnlinePlayers() {
|
||||
return getServer().map(server -> {
|
||||
Collection<Player> players = server.getOnlinePlayers();
|
||||
List<UUID> list = new ArrayList<>(players.size());
|
||||
for (Player player : players) {
|
||||
list.add(player.getUniqueId());
|
||||
}
|
||||
return list;
|
||||
}).orElse(Collections.emptyList());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -48,10 +48,12 @@ import org.slf4j.Logger;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Instant;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* Bootstrap plugin for LuckPerms running on Velocity.
|
||||
@ -226,13 +228,23 @@ public class LPVelocityBootstrap implements LuckPermsBootstrap {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<String> getPlayerList() {
|
||||
return this.proxy.getAllPlayers().stream().map(Player::getUsername);
|
||||
public Collection<String> getPlayerList() {
|
||||
Collection<Player> players = this.proxy.getAllPlayers();
|
||||
List<String> list = new ArrayList<>(players.size());
|
||||
for (Player player : players) {
|
||||
list.add(player.getUsername());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Stream<UUID> getOnlinePlayers() {
|
||||
return this.proxy.getAllPlayers().stream().map(Player::getUniqueId);
|
||||
public Collection<UUID> getOnlinePlayers() {
|
||||
Collection<Player> players = this.proxy.getAllPlayers();
|
||||
List<UUID> list = new ArrayList<>(players.size());
|
||||
for (Player player : players) {
|
||||
list.add(player.getUniqueId());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user