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;
|
package me.lucko.luckperms.common.storage;
|
||||||
|
|
||||||
import com.google.common.base.Throwables;
|
import com.google.common.base.Throwables;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.HeldPermission;
|
import me.lucko.luckperms.api.HeldPermission;
|
||||||
import me.lucko.luckperms.api.LogEntry;
|
import me.lucko.luckperms.api.LogEntry;
|
||||||
@ -181,7 +182,11 @@ public class AbstractStorage implements Storage {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<List<HeldPermission<UUID>>> getUsersWithPermission(String permission) {
|
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
|
@Override
|
||||||
@ -229,7 +234,11 @@ public class AbstractStorage implements Storage {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<List<HeldPermission<String>>> getGroupsWithPermission(String permission) {
|
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
|
@Override
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.storage.dao.file;
|
package me.lucko.luckperms.common.storage.dao.file;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
import me.lucko.luckperms.api.HeldPermission;
|
import me.lucko.luckperms.api.HeldPermission;
|
||||||
@ -450,7 +449,7 @@ public abstract class ConfigurateDao extends AbstractDao {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<HeldPermission<UUID>> getUsersWithPermission(String permission) throws Exception {
|
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());
|
File[] files = getDirectory(StorageLocation.USER).listFiles(getFileTypeFilter());
|
||||||
if (files == null) {
|
if (files == null) {
|
||||||
throw new IllegalStateException("Users directory matched no files.");
|
throw new IllegalStateException("Users directory matched no files.");
|
||||||
@ -472,7 +471,7 @@ public abstract class ConfigurateDao extends AbstractDao {
|
|||||||
throw reportException(file.getName(), e);
|
throw reportException(file.getName(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return held.build();
|
return held;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -605,7 +604,7 @@ public abstract class ConfigurateDao extends AbstractDao {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<HeldPermission<String>> getGroupsWithPermission(String permission) throws Exception {
|
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());
|
File[] files = getDirectory(StorageLocation.GROUP).listFiles(getFileTypeFilter());
|
||||||
if (files == null) {
|
if (files == null) {
|
||||||
throw new IllegalStateException("Groups directory matched no files.");
|
throw new IllegalStateException("Groups directory matched no files.");
|
||||||
@ -627,7 +626,7 @@ public abstract class ConfigurateDao extends AbstractDao {
|
|||||||
throw reportException(file.getName(), e);
|
throw reportException(file.getName(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return held.build();
|
return held;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -26,7 +26,6 @@
|
|||||||
package me.lucko.luckperms.common.storage.dao.mongodb;
|
package me.lucko.luckperms.common.storage.dao.mongodb;
|
||||||
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import com.mongodb.MongoClient;
|
import com.mongodb.MongoClient;
|
||||||
import com.mongodb.MongoClientOptions;
|
import com.mongodb.MongoClientOptions;
|
||||||
import com.mongodb.MongoCredential;
|
import com.mongodb.MongoCredential;
|
||||||
@ -311,7 +310,7 @@ public class MongoDao extends AbstractDao {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<HeldPermission<UUID>> getUsersWithPermission(String permission) {
|
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");
|
MongoCollection<Document> c = this.database.getCollection(this.prefix + "users");
|
||||||
try (MongoCursor<Document> cursor = c.find().iterator()) {
|
try (MongoCursor<Document> cursor = c.find().iterator()) {
|
||||||
while (cursor.hasNext()) {
|
while (cursor.hasNext()) {
|
||||||
@ -327,7 +326,7 @@ public class MongoDao extends AbstractDao {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return held.build();
|
return held;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -438,7 +437,7 @@ public class MongoDao extends AbstractDao {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<HeldPermission<String>> getGroupsWithPermission(String permission) {
|
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");
|
MongoCollection<Document> c = this.database.getCollection(this.prefix + "groups");
|
||||||
try (MongoCursor<Document> cursor = c.find().iterator()) {
|
try (MongoCursor<Document> cursor = c.find().iterator()) {
|
||||||
while (cursor.hasNext()) {
|
while (cursor.hasNext()) {
|
||||||
@ -454,7 +453,7 @@ public class MongoDao extends AbstractDao {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return held.build();
|
return held;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
package me.lucko.luckperms.common.storage.dao.sql;
|
package me.lucko.luckperms.common.storage.dao.sql;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
@ -510,7 +509,7 @@ public class SqlDao extends AbstractDao {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<HeldPermission<UUID>> getUsersWithPermission(String permission) throws SQLException {
|
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 (Connection c = this.provider.getConnection()) {
|
||||||
try (PreparedStatement ps = c.prepareStatement(this.prefix.apply(USER_PERMISSIONS_SELECT_PERMISSION))) {
|
try (PreparedStatement ps = c.prepareStatement(this.prefix.apply(USER_PERMISSIONS_SELECT_PERMISSION))) {
|
||||||
ps.setString(1, permission);
|
ps.setString(1, permission);
|
||||||
@ -529,7 +528,7 @@ public class SqlDao extends AbstractDao {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return held.build();
|
return held;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -754,7 +753,7 @@ public class SqlDao extends AbstractDao {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<HeldPermission<String>> getGroupsWithPermission(String permission) throws SQLException {
|
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 (Connection c = this.provider.getConnection()) {
|
||||||
try (PreparedStatement ps = c.prepareStatement(this.prefix.apply(GROUP_PERMISSIONS_SELECT_PERMISSION))) {
|
try (PreparedStatement ps = c.prepareStatement(this.prefix.apply(GROUP_PERMISSIONS_SELECT_PERMISSION))) {
|
||||||
ps.setString(1, permission);
|
ps.setString(1, permission);
|
||||||
@ -773,7 +772,7 @@ public class SqlDao extends AbstractDao {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return held.build();
|
return held;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user