Mark reports as expired when an expired report is detected

Also wrote JavaDocs for expireReport and saveReport methods.
This commit is contained in:
Keir Nellyer 2016-07-09 15:47:31 -04:00
parent d7736e9e02
commit ac95a59f81
2 changed files with 52 additions and 8 deletions

View File

@ -226,6 +226,32 @@ public class ReportManager
});
}
/**
* Marks a report as expired.
*
* This essentially closes the report with the result {@link ReportResultType#EXPIRED}
* and no string reason.
*
* A report should be marked as expired when it has a priority <= 0 and is not
* currently being handled.
*
* This is done to keep the database clean and reduce future query times as expired
* reports can easily be ignored.
*
* @param report the report to mark as expired
* @return a future which can be used to monitor the progress of the task
*/
public CompletableFuture<Void> expireReport(Report report)
{
return closeReport(report, null, new ReportResult(ReportResultType.EXPIRED, null));
}
/**
* Writes all report data to the database.
*
* @param report the report to write to the database
* @return future which when complete, returns the reports id
*/
public CompletableFuture<Long> saveReport(Report report)
{
CompletableFuture<Long> updateCompletableFuture = _reportRepository.updateReport(report);
@ -286,7 +312,20 @@ public class ReportManager
}
else
{
return calculatePriority(report).thenApply(priority -> priority > 0);
return calculatePriority(report).thenApply(priority ->
{
if (priority <= 0)
{
// mark the report as expired to keep the database clean
// and reduce future query time
expireReport(report);
return false;
}
else
{
return true;
}
});
}
}
@ -356,12 +395,6 @@ public class ReportManager
priority += categoryReputation * serverWeight * ageImpact;
}
if (priority <= 0)
{
System.out.println("Closing report due to expiration (#" + report.getId().orElse((long) -1) + ").");
closeReport(report, null, new ReportResult(ReportResultType.EXPIRED, null));
}
return priority;
});
}

View File

@ -46,7 +46,18 @@ public class ReportHandleCommand extends CommandBase<ReportPlugin>
reportRepository.getUnhandledReports().thenCompose(reportRepository::getReports).thenAccept(reports ->
CompletableFuture.allOf(reports.stream().map(report ->
reportManager.calculatePriority(report).thenAccept(priority ->
reportPriorities.put(report, priority)
{
if (priority > 0)
{
reportPriorities.put(report, priority);
}
else
{
// mark the report as expired to keep the database clean
// and reduce future query time
reportManager.expireReport(report);
}
}
)
).toArray(CompletableFuture[]::new)).join()
).thenApply(aVoid ->