From 7e7268bb5a2725a4ea39dbe2be3b076d0f154247 Mon Sep 17 00:00:00 2001 From: Luck Date: Wed, 7 Feb 2018 18:03:25 +0000 Subject: [PATCH] Filter expired entries from user/group bulk permission search results (#736) --- .../luckperms/common/storage/AbstractStorage.java | 13 +++++++++++-- .../common/storage/dao/file/ConfigurateDao.java | 9 ++++----- .../common/storage/dao/mongodb/MongoDao.java | 9 ++++----- .../luckperms/common/storage/dao/sql/SqlDao.java | 9 ++++----- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/AbstractStorage.java b/common/src/main/java/me/lucko/luckperms/common/storage/AbstractStorage.java index b6dc7e76..450ecaa5 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/AbstractStorage.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/AbstractStorage.java @@ -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>> getUsersWithPermission(String permission) { - return makeFuture(() -> this.dao.getUsersWithPermission(permission)); + return makeFuture(() -> { + List> 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>> getGroupsWithPermission(String permission) { - return makeFuture(() -> this.dao.getGroupsWithPermission(permission)); + return makeFuture(() -> { + List> result = this.dao.getGroupsWithPermission(permission); + result.removeIf(entry -> entry.asNode().hasExpired()); + return ImmutableList.copyOf(result); + }); } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/dao/file/ConfigurateDao.java b/common/src/main/java/me/lucko/luckperms/common/storage/dao/file/ConfigurateDao.java index b8927126..2b957dfb 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/dao/file/ConfigurateDao.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/dao/file/ConfigurateDao.java @@ -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> getUsersWithPermission(String permission) throws Exception { - ImmutableList.Builder> held = ImmutableList.builder(); + List> 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> getGroupsWithPermission(String permission) throws Exception { - ImmutableList.Builder> held = ImmutableList.builder(); + List> 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 diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/dao/mongodb/MongoDao.java b/common/src/main/java/me/lucko/luckperms/common/storage/dao/mongodb/MongoDao.java index b85b5ff2..15a8d919 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/dao/mongodb/MongoDao.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/dao/mongodb/MongoDao.java @@ -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> getUsersWithPermission(String permission) { - ImmutableList.Builder> held = ImmutableList.builder(); + List> held = new ArrayList<>(); MongoCollection c = this.database.getCollection(this.prefix + "users"); try (MongoCursor 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> getGroupsWithPermission(String permission) { - ImmutableList.Builder> held = ImmutableList.builder(); + List> held = new ArrayList<>(); MongoCollection c = this.database.getCollection(this.prefix + "groups"); try (MongoCursor cursor = c.find().iterator()) { while (cursor.hasNext()) { @@ -454,7 +453,7 @@ public class MongoDao extends AbstractDao { } } } - return held.build(); + return held; } @Override diff --git a/common/src/main/java/me/lucko/luckperms/common/storage/dao/sql/SqlDao.java b/common/src/main/java/me/lucko/luckperms/common/storage/dao/sql/SqlDao.java index 0dc2ace5..b9ceee5d 100644 --- a/common/src/main/java/me/lucko/luckperms/common/storage/dao/sql/SqlDao.java +++ b/common/src/main/java/me/lucko/luckperms/common/storage/dao/sql/SqlDao.java @@ -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> getUsersWithPermission(String permission) throws SQLException { - ImmutableList.Builder> held = ImmutableList.builder(); + List> 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> getGroupsWithPermission(String permission) throws SQLException { - ImmutableList.Builder> held = ImmutableList.builder(); + List> 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