diff --git a/eos/saveddata/fit.py b/eos/saveddata/fit.py index a58946009..b7f7a4f2f 100644 --- a/eos/saveddata/fit.py +++ b/eos/saveddata/fit.py @@ -29,6 +29,7 @@ from eos.saveddata.module import State from eos.saveddata.mode import Mode import eos.db import time +import copy from utils.timer import Timer import logging @@ -414,14 +415,23 @@ class Fit(object): pass def calculateModifiedAttributes(self, targetFit=None, withBoosters=False, dirtyStorage=None): - timer = Timer('Fit: %d, %s'%(self.ID, self.name), logger) + timer = Timer('Fit: {}, {}'.format(self.ID, self.name), logger) logger.debug("Starting fit calculation on: %d %s (%s)" % (self.ID, self.name, self.ship.item.name)) + shadow = False if targetFit: logger.debug("Applying projections to target: %d %s (%s)", targetFit.ID, targetFit.name, targetFit.ship.item.name) projectionInfo = self.getProjectionInfo(targetFit.ID) logger.debug("ProjectionInfo: %s", ', '.join("%s: %s" % item for item in vars(projectionInfo).items())) + if self == targetFit: + shadow = True + self = copy.deepcopy(self) + logger.debug("Handling self projection - making shadow copy of fit. %s => %s", projectionInfo.source_fit, self) + # we rollback because when we copy a fit, flush() is called to + # properly handle projection updates. However, we do not want to + # save this fit to the database, so we can immediately rollback + eos.db.saveddata_session.rollback() refreshBoosts = False if withBoosters is True: @@ -495,6 +505,10 @@ class Fit(object): timer.checkpoint('Done with fit calculation') + if shadow: + logger.debug("Delete shadow fit object") + del self + def fill(self): """ Fill this fit's module slots with enough dummy slots so that all slots are used. diff --git a/service/fit.py b/service/fit.py index 40cbe8eb0..ac641a2bd 100644 --- a/service/fit.py +++ b/service/fit.py @@ -320,9 +320,6 @@ class Fit(object): eager=("attributes", "group.category")) if isinstance(thing, eos.types.Fit): - if thing.ID == fitID: - return - if thing in fit.projectedFits: return