Fix issue an old un-closed but expired report may be re-opened and cause issues

This commit is contained in:
Keir Nellyer 2016-06-11 13:59:53 +01:00
parent 197acee4ae
commit ed50e09a6e
2 changed files with 14 additions and 7 deletions

View File

@ -69,7 +69,7 @@ public class ReportManager
_serverName = serverName;
_serverWeight = serverWeight;
_reportRepository = new ReportRepository(javaPlugin);
_reportRepository = new ReportRepository(javaPlugin, this);
_reportRepository.initialize();
_reportProfileRepository = new ReportProfileRepository(javaPlugin);
@ -295,7 +295,6 @@ public class ReportManager
int playerId = _clientManager.Get(player).getAccountId();
_reportRepository.getOngoingReport(playerId)
.thenCompose(_reportRepository::getReport)
.thenAccept(report ->
{
if (report != null)
@ -313,7 +312,6 @@ public class ReportManager
int playerId = _clientManager.Get(player).getAccountId();
_reportRepository.getOngoingReport(playerId)
.thenCompose(_reportRepository::getReport)
.thenAccept(report ->
{
if (report != null)

View File

@ -87,14 +87,17 @@ public class ReportRepository extends MinecraftRepository
private static final String GET_ACCOUNT_UUID = "SELECT id, uuid FROM accounts" +
" WHERE id IN (%s);";
private final ReportManager _reportManager;
private final Cache<Integer, Report> _cachedReports = CacheBuilder.newBuilder()
.maximumSize(1000)
.expireAfterAccess(5, TimeUnit.MINUTES)
.build();
public ReportRepository(JavaPlugin plugin)
public ReportRepository(JavaPlugin plugin, ReportManager reportManager)
{
super(plugin, DBPool.getAccount());
_reportManager = reportManager;
}
@Override
@ -214,7 +217,7 @@ public class ReportRepository extends MinecraftRepository
}
// todo check if expired
public CompletableFuture<Integer> getOngoingReport(int suspectId)
public CompletableFuture<Report> getOngoingReport(int suspectId)
{
return CompletableFuture.supplyAsync(() ->
{
@ -224,9 +227,15 @@ public class ReportRepository extends MinecraftRepository
preparedStatement.setInt(1, suspectId);
ResultSet resultSet = preparedStatement.executeQuery();
if (resultSet.next())
while (resultSet.next())
{
return resultSet.getInt("id");
int id = resultSet.getInt("id");
Report report = getReport(id).join();
if (_reportManager.isActiveReport(report).join())
{
return report;
}
}
}
catch (SQLException e)