From: David ‘Bombe’ Roden Date: Thu, 27 Mar 2014 16:48:30 +0000 (+0100) Subject: Load last state later, and only if required. X-Git-Tag: v2~238 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=e2a7128bc811dc0bffb11fbe4d9966f9bf80645f;p=rhynodge.git Load last state later, and only if required. --- 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);