Fix AbstractUserManager to only load users once in #loadAllUsers

This commit is contained in:
Luck 2020-02-03 00:44:08 +00:00
parent 7a624fb449
commit 9546987970
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
4 changed files with 20 additions and 26 deletions

View File

@ -34,15 +34,18 @@ import me.lucko.luckperms.common.model.manager.AbstractManager;
import me.lucko.luckperms.common.model.manager.group.GroupManager; import me.lucko.luckperms.common.model.manager.group.GroupManager;
import me.lucko.luckperms.common.node.types.Inheritance; import me.lucko.luckperms.common.node.types.Inheritance;
import me.lucko.luckperms.common.plugin.LuckPermsPlugin; import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import me.lucko.luckperms.common.util.Iterators;
import net.luckperms.api.model.data.DataType; import net.luckperms.api.model.data.DataType;
import net.luckperms.api.node.Node; import net.luckperms.api.node.Node;
import net.luckperms.api.node.types.InheritanceNode; import net.luckperms.api.node.types.InheritanceNode;
import java.util.Optional; import java.util.Optional;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
public abstract class AbstractUserManager<T extends User> extends AbstractManager<UUID, User, T> implements UserManager<T> { public abstract class AbstractUserManager<T extends User> extends AbstractManager<UUID, User, T> implements UserManager<T> {
@ -132,16 +135,17 @@ public abstract class AbstractUserManager<T extends User> extends AbstractManage
} }
@Override @Override
public CompletableFuture<Void> updateAllUsers() { public CompletableFuture<Void> loadAllUsers() {
return CompletableFuture.runAsync( Set<UUID> ids = Stream.concat(
() -> {
Stream.concat(
getAll().keySet().stream(), getAll().keySet().stream(),
this.plugin.getBootstrap().getOnlinePlayers() this.plugin.getBootstrap().getOnlinePlayers()
).forEach(u -> this.plugin.getStorage().loadUser(u, null).join()); ).collect(Collectors.toSet());
},
this.plugin.getBootstrap().getScheduler().async() return CompletableFuture.runAsync(() -> {
); Iterators.tryIterate(ids, id -> {
this.plugin.getStorage().loadUser(id, null).join();
});
}, this.plugin.getBootstrap().getScheduler().async());
} }
@Override @Override

View File

@ -77,7 +77,7 @@ public interface UserManager<T extends User> extends Manager<UUID, User, T> {
/** /**
* Reloads the data of all *online* users * Reloads the data of all *online* users
*/ */
CompletableFuture<Void> updateAllUsers(); CompletableFuture<Void> loadAllUsers();
/** /**
* Invalidates the cached data for *loaded* users. * Invalidates the cached data for *loaded* users.

View File

@ -189,7 +189,7 @@ public abstract class AbstractLuckPermsPlugin implements LuckPermsPlugin {
// run an update instantly. // run an update instantly.
getLogger().info("Performing initial data load..."); getLogger().info("Performing initial data load...");
try { try {
new SyncTask(this, true).run(); new SyncTask(this).run();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -31,7 +31,6 @@ import me.lucko.luckperms.common.plugin.LuckPermsPlugin;
import net.luckperms.api.event.cause.CreationCause; import net.luckperms.api.event.cause.CreationCause;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
@ -42,14 +41,8 @@ import java.util.concurrent.TimeUnit;
public class SyncTask implements Runnable { public class SyncTask implements Runnable {
private final LuckPermsPlugin plugin; private final LuckPermsPlugin plugin;
/** public SyncTask(LuckPermsPlugin plugin) {
* If this task is being called before the server has fully started
*/
private final boolean initialUpdate;
public SyncTask(LuckPermsPlugin plugin, boolean initialUpdate) {
this.plugin = plugin; this.plugin = plugin;
this.initialUpdate = initialUpdate;
} }
/** /**
@ -72,11 +65,8 @@ public class SyncTask implements Runnable {
// Reload all tracks // Reload all tracks
this.plugin.getStorage().loadAllTracks().join(); this.plugin.getStorage().loadAllTracks().join();
// Refresh all online users. // Reload all online users.
CompletableFuture<Void> userUpdateFut = this.plugin.getUserManager().updateAllUsers(); this.plugin.getUserManager().loadAllUsers().join();
if (!this.initialUpdate) {
userUpdateFut.join();
}
this.plugin.performPlatformDataSync(); this.plugin.performPlatformDataSync();
@ -97,7 +87,7 @@ public class SyncTask implements Runnable {
@Override @Override
protected Void perform() { protected Void perform() {
new SyncTask(this.plugin, false).run(); new SyncTask(this.plugin).run();
return null; return null;
} }
} }