mirror of
https://github.com/LuckPerms/LuckPerms.git
synced 2024-11-24 11:38:40 +01:00
Filter expired entries from user/group bulk permission search results (#736)
This commit is contained in:
parent
173286d404
commit
7e7268bb5a
@ -26,6 +26,7 @@
|
||||
package me.lucko.luckperms.common.storage;
|
||||
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import me.lucko.luckperms.api.HeldPermission;
|
||||
import me.lucko.luckperms.api.LogEntry;
|
||||
@ -181,7 +182,11 @@ public class AbstractStorage implements Storage {
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<HeldPermission<UUID>>> getUsersWithPermission(String permission) {
|
||||
return makeFuture(() -> this.dao.getUsersWithPermission(permission));
|
||||
return makeFuture(() -> {
|
||||
List<HeldPermission<UUID>> result = this.dao.getUsersWithPermission(permission);
|
||||
result.removeIf(entry -> entry.asNode().hasExpired());
|
||||
return ImmutableList.copyOf(result);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -229,7 +234,11 @@ public class AbstractStorage implements Storage {
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<HeldPermission<String>>> getGroupsWithPermission(String permission) {
|
||||
return makeFuture(() -> this.dao.getGroupsWithPermission(permission));
|
||||
return makeFuture(() -> {
|
||||
List<HeldPermission<String>> result = this.dao.getGroupsWithPermission(permission);
|
||||
result.removeIf(entry -> entry.asNode().hasExpired());
|
||||
return ImmutableList.copyOf(result);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,7 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.storage.dao.file;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
import me.lucko.luckperms.api.HeldPermission;
|
||||
@ -450,7 +449,7 @@ public abstract class ConfigurateDao extends AbstractDao {
|
||||
|
||||
@Override
|
||||
public List<HeldPermission<UUID>> getUsersWithPermission(String permission) throws Exception {
|
||||
ImmutableList.Builder<HeldPermission<UUID>> held = ImmutableList.builder();
|
||||
List<HeldPermission<UUID>> held = new ArrayList<>();
|
||||
File[] files = getDirectory(StorageLocation.USER).listFiles(getFileTypeFilter());
|
||||
if (files == null) {
|
||||
throw new IllegalStateException("Users directory matched no files.");
|
||||
@ -472,7 +471,7 @@ public abstract class ConfigurateDao extends AbstractDao {
|
||||
throw reportException(file.getName(), e);
|
||||
}
|
||||
}
|
||||
return held.build();
|
||||
return held;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -605,7 +604,7 @@ public abstract class ConfigurateDao extends AbstractDao {
|
||||
|
||||
@Override
|
||||
public List<HeldPermission<String>> getGroupsWithPermission(String permission) throws Exception {
|
||||
ImmutableList.Builder<HeldPermission<String>> held = ImmutableList.builder();
|
||||
List<HeldPermission<String>> held = new ArrayList<>();
|
||||
File[] files = getDirectory(StorageLocation.GROUP).listFiles(getFileTypeFilter());
|
||||
if (files == null) {
|
||||
throw new IllegalStateException("Groups directory matched no files.");
|
||||
@ -627,7 +626,7 @@ public abstract class ConfigurateDao extends AbstractDao {
|
||||
throw reportException(file.getName(), e);
|
||||
}
|
||||
}
|
||||
return held.build();
|
||||
return held;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -26,7 +26,6 @@
|
||||
package me.lucko.luckperms.common.storage.dao.mongodb;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mongodb.MongoClient;
|
||||
import com.mongodb.MongoClientOptions;
|
||||
import com.mongodb.MongoCredential;
|
||||
@ -311,7 +310,7 @@ public class MongoDao extends AbstractDao {
|
||||
|
||||
@Override
|
||||
public List<HeldPermission<UUID>> getUsersWithPermission(String permission) {
|
||||
ImmutableList.Builder<HeldPermission<UUID>> held = ImmutableList.builder();
|
||||
List<HeldPermission<UUID>> held = new ArrayList<>();
|
||||
MongoCollection<Document> c = this.database.getCollection(this.prefix + "users");
|
||||
try (MongoCursor<Document> cursor = c.find().iterator()) {
|
||||
while (cursor.hasNext()) {
|
||||
@ -327,7 +326,7 @@ public class MongoDao extends AbstractDao {
|
||||
}
|
||||
}
|
||||
}
|
||||
return held.build();
|
||||
return held;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -438,7 +437,7 @@ public class MongoDao extends AbstractDao {
|
||||
|
||||
@Override
|
||||
public List<HeldPermission<String>> getGroupsWithPermission(String permission) {
|
||||
ImmutableList.Builder<HeldPermission<String>> held = ImmutableList.builder();
|
||||
List<HeldPermission<String>> held = new ArrayList<>();
|
||||
MongoCollection<Document> c = this.database.getCollection(this.prefix + "groups");
|
||||
try (MongoCursor<Document> cursor = c.find().iterator()) {
|
||||
while (cursor.hasNext()) {
|
||||
@ -454,7 +453,7 @@ public class MongoDao extends AbstractDao {
|
||||
}
|
||||
}
|
||||
}
|
||||
return held.build();
|
||||
return held;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,7 +25,6 @@
|
||||
|
||||
package me.lucko.luckperms.common.storage.dao.sql;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
@ -510,7 +509,7 @@ public class SqlDao extends AbstractDao {
|
||||
|
||||
@Override
|
||||
public List<HeldPermission<UUID>> getUsersWithPermission(String permission) throws SQLException {
|
||||
ImmutableList.Builder<HeldPermission<UUID>> held = ImmutableList.builder();
|
||||
List<HeldPermission<UUID>> held = new ArrayList<>();
|
||||
try (Connection c = this.provider.getConnection()) {
|
||||
try (PreparedStatement ps = c.prepareStatement(this.prefix.apply(USER_PERMISSIONS_SELECT_PERMISSION))) {
|
||||
ps.setString(1, permission);
|
||||
@ -529,7 +528,7 @@ public class SqlDao extends AbstractDao {
|
||||
}
|
||||
}
|
||||
}
|
||||
return held.build();
|
||||
return held;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -754,7 +753,7 @@ public class SqlDao extends AbstractDao {
|
||||
|
||||
@Override
|
||||
public List<HeldPermission<String>> getGroupsWithPermission(String permission) throws SQLException {
|
||||
ImmutableList.Builder<HeldPermission<String>> held = ImmutableList.builder();
|
||||
List<HeldPermission<String>> held = new ArrayList<>();
|
||||
try (Connection c = this.provider.getConnection()) {
|
||||
try (PreparedStatement ps = c.prepareStatement(this.prefix.apply(GROUP_PERMISSIONS_SELECT_PERMISSION))) {
|
||||
ps.setString(1, permission);
|
||||
@ -773,7 +772,7 @@ public class SqlDao extends AbstractDao {
|
||||
}
|
||||
}
|
||||
}
|
||||
return held.build();
|
||||
return held;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user