Run ReportPurgeTask asynchronously
This prevents the task from hanging the server which may be an issue when a large amount of reports exist.
This commit is contained in:
parent
57e9cd6e19
commit
713263214f
@ -26,9 +26,8 @@ public class ReportPlugin extends MiniPlugin
|
|||||||
_reportManager = reportManager;
|
_reportManager = reportManager;
|
||||||
|
|
||||||
// purge old reports every minute
|
// purge old reports every minute
|
||||||
// TODO does this need to be async?
|
|
||||||
_reportPurgeTask = new ReportPurgeTask(_reportManager);
|
_reportPurgeTask = new ReportPurgeTask(_reportManager);
|
||||||
_reportPurgeTask.runTaskTimer(getPlugin(), 20L * 10, 20L * 60);
|
_reportPurgeTask.runTaskTimerAsynchronously(getPlugin(), 20L * 10, 20L * 60);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package mineplex.core.report.task;
|
package mineplex.core.report.task;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import mineplex.core.common.util.C;
|
import mineplex.core.common.util.C;
|
||||||
@ -21,7 +23,7 @@ public class ReportPurgeTask extends BukkitRunnable
|
|||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
for (int reportId : _reportManager.getActiveReports())
|
for (int reportId : new ArrayList<>(_reportManager.getActiveReports())) // create copy as this will be run async
|
||||||
{
|
{
|
||||||
Report report = _reportManager.getReport(reportId);
|
Report report = _reportManager.getReport(reportId);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user