From e2a7128bc811dc0bffb11fbe4d9966f9bf80645f Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 27 Mar 2014 17:48:30 +0100 Subject: [PATCH] Load last state later, and only if required. --- src/main/java/net/pterodactylus/rhynodge/engine/Engine.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/pterodactylus/rhynodge/engine/Engine.java b/src/main/java/net/pterodactylus/rhynodge/engine/Engine.java index 861bfba..af64e04 100644 --- a/src/main/java/net/pterodactylus/rhynodge/engine/Engine.java +++ b/src/main/java/net/pterodactylus/rhynodge/engine/Engine.java @@ -121,8 +121,6 @@ public class Engine extends AbstractExecutionThreadService { logger.debug(format("Next Reaction: %s.", reactionName)); /* wait until the next reaction has to run. */ - Optional lastState = stateManager.loadLastState(reactionName); - int lastStateFailCount = lastState.isPresent() ? lastState.get().failCount() : 0; long waitTime = nextReaction.get().getNextTime() - System.currentTimeMillis(); logger.debug(format("Time to wait for next Reaction: %d millseconds.", waitTime)); if (waitTime > 0) { @@ -142,7 +140,8 @@ public class Engine extends AbstractExecutionThreadService { } } if (!state.success()) { - state.setFailCount(lastStateFailCount + 1); + Optional lastState = stateManager.loadLastState(reactionName); + state.setFailCount(lastState.map(net.pterodactylus.rhynodge.State::failCount).orElse(0) + 1); } Optional lastSuccessfulState = stateManager.loadLastSuccessfulState(reactionName); -- 2.7.4