diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/data/ReportProfileRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/report/data/ReportProfileRepository.java index 24736e16c..548d9d531 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/data/ReportProfileRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/data/ReportProfileRepository.java @@ -13,6 +13,7 @@ import java.util.stream.Collectors; import org.bukkit.plugin.java.JavaPlugin; import com.google.common.base.Preconditions; +import mineplex.core.common.util.UtilFuture; import mineplex.core.report.ReportCategory; import mineplex.core.report.ReportResultType; import mineplex.serverdata.database.DBPool; @@ -37,9 +38,16 @@ public class ReportProfileRepository _plugin = plugin; } - public List> getProfiles(Collection accountIds) + public CompletableFuture> getProfiles(Collection accountIds) { - return accountIds.stream().map(this::getProfile).filter(profile -> profile != null).collect(Collectors.toList()); + return UtilFuture.sequence( + accountIds.stream() + .map(this::getProfile) + .collect(Collectors.toList()) + ).thenApply(profiles -> + profiles.stream().filter(profile -> profile != null) + .collect(Collectors.toList()) + ); } public CompletableFuture getProfile(int accountId) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/data/ReportRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/report/data/ReportRepository.java index 0cf220455..f0fc69aa1 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/data/ReportRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/data/ReportRepository.java @@ -26,6 +26,7 @@ import java.util.stream.Collectors; import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.mysql.jdbc.Statement; +import mineplex.core.common.util.UtilFuture; import mineplex.core.common.util.UtilTime; import mineplex.core.report.ReportCategory; import mineplex.core.report.ReportManager; @@ -184,11 +185,15 @@ public class ReportRepository public CompletableFuture> getReports(Collection reportIds) { - return CompletableFuture.supplyAsync(() -> reportIds.parallelStream() - .map(ReportRepository.this::getReport) - .map(CompletableFuture::join) - .filter(report -> report != null) - .collect(Collectors.toList())); + return UtilFuture.sequence( + reportIds.stream() + .map(this::getReport) + .collect(Collectors.toList()) + ).thenApply(reports -> + reports.stream() + .filter(report -> report != null) + .collect(Collectors.toList()) + ); } public CompletableFuture getReport(long reportId) @@ -256,7 +261,7 @@ public class ReportRepository future.exceptionally(throwable -> { - _logger.log(Level.SEVERE, "Error fetching report.", throwable); + _logger.log(Level.SEVERE, "Error fetching report (id: " + reportId + ").", throwable); return null; });