From c9c29da803f0e1da7bdab66eaab05c17f968ab32 Mon Sep 17 00:00:00 2001 From: blitzman Date: Sat, 11 Feb 2017 23:55:19 -0500 Subject: [PATCH] Avoid fit recalc when setting state has no effect --- service/fit.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/service/fit.py b/service/fit.py index ea05e3277..2e020e960 100644 --- a/service/fit.py +++ b/service/fit.py @@ -940,21 +940,27 @@ class Fit(object): self.recalc(fit) def toggleModulesState(self, fitID, base, modules, click): + changed = False proposedState = self.__getProposedState(base, click) + if proposedState != base.state: + changed = True base.state = proposedState for mod in modules: if mod != base: - mod.state = self.__getProposedState(mod, click, - proposedState) + p = self.__getProposedState(mod, click, proposedState) + mod.state = p + if p != mod.state: + changed = True - eos.db.commit() - fit = eos.db.getFit(fitID) + if changed: + eos.db.commit() + fit = eos.db.getFit(fitID) - # As some items may affect state-limiting attributes of the ship, calculate new attributes first - self.recalc(fit) - # Then, check states of all modules and change where needed. This will recalc if needed - self.checkStates(fit, base) + # As some items may affect state-limiting attributes of the ship, calculate new attributes first + self.recalc(fit) + # Then, check states of all modules and change where needed. This will recalc if needed + self.checkStates(fit, base) # Old state : New State localMap = {