Fix getProfiles and getReports methods
This commit is contained in:
parent
65e8b92c1a
commit
4ed51b5747
@ -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<CompletableFuture<ReportProfile>> getProfiles(Collection<Integer> accountIds)
|
||||
public CompletableFuture<List<ReportProfile>> getProfiles(Collection<Integer> 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<ReportProfile> getProfile(int accountId)
|
||||
|
@ -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<List<Report>> getReports(Collection<Integer> 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<Report> 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;
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user