Separate characters from Fit relationship and create new character session. At this point, changes to characters do not persist. Efforts must still be made to focus on creating a character save function as well as ensure characters that are dirty are loaded correctly for fresh fits.

This commit is contained in:
blitzmann
2015-09-09 19:08:38 -04:00
parent 492776c5a8
commit 3521b3887d
4 changed files with 14 additions and 15 deletions

View File

@@ -58,7 +58,9 @@ if saveddata_connectionstring is not None:
saveddata_meta = MetaData()
saveddata_meta.bind = saveddata_engine
saveddata_session = sessionmaker(bind=saveddata_engine, autoflush=False, expire_on_commit=False)()
base = sessionmaker(bind=saveddata_engine, autoflush=False, expire_on_commit=False)
saveddata_session = base()
character_session = base()
# Lock controlling any changes introduced to session
sd_lock = threading.Lock()
@@ -75,7 +77,7 @@ from eos.db.saveddata.queries import getUser, getCharacter, getFit, getFitsWithS
getFitList, getFleetList, getFleet, save, remove, commit, add, \
getCharactersForUser, getMiscData, getSquadsIDsWithFitID, getWing, \
getSquad, getBoosterFits, getProjectedFits, getTargetResistsList, getTargetResists,\
clearPrices, countAllFits
clearPrices, countAllFits, getCharacter
#If using in memory saveddata, you'll want to reflect it so the data structure is good.
if config.saveddata_connectionstring == "sqlite:///:memory:":

View File

@@ -138,9 +138,6 @@ mapper(Fit, fits_table,
primaryjoin=fitImplants_table.c.fitID == fits_table.c.ID,
secondaryjoin=fitImplants_table.c.implantID == Implant.ID,
secondary=fitImplants_table),
"_Fit__character": relation(
Character,
backref="fits"),
"_Fit__damagePattern": relation(DamagePattern),
"_Fit__targetResists": relation(TargetResists),
"projectedOnto": relationship(

View File

@@ -18,7 +18,7 @@
#===============================================================================
from eos.db.util import processEager, processWhere
from eos.db import saveddata_session, sd_lock
from eos.db import saveddata_session, character_session, sd_lock
from eos.types import User, Character, Fit, Price, DamagePattern, Fleet, MiscData, Wing, Squad, TargetResists
from eos.db.saveddata.fleet import squadmembers_table
from eos.db.saveddata.fit import projectedFits_table
@@ -144,16 +144,14 @@ def getUser(lookfor, eager=None):
def getCharacter(lookfor, eager=None):
if isinstance(lookfor, int):
if eager is None:
with sd_lock:
character = saveddata_session.query(Character).get(lookfor)
character = character_session.query(Character).get(lookfor)
else:
eager = processEager(eager)
with sd_lock:
character = saveddata_session.query(Character).options(*eager).filter(Character.ID == lookfor).first()
character = character_session.query(Character).options(*eager).filter(Character.ID == lookfor).first()
print character
elif isinstance(lookfor, basestring):
eager = processEager(eager)
with sd_lock:
character = saveddata_session.query(Character).options(*eager).filter(Character.name == lookfor).first()
character = character_session.query(Character).options(*eager).filter(Character.name == lookfor).first()
else:
raise TypeError("Need integer or string as argument")
return character
@@ -161,14 +159,14 @@ def getCharacter(lookfor, eager=None):
def getCharacterList(eager=None):
eager = processEager(eager)
with sd_lock:
characters = saveddata_session.query(Character).options(*eager).all()
characters = character_session.query(Character).options(*eager).all()
return characters
def getCharactersForUser(lookfor, eager=None):
if isinstance(lookfor, int):
eager = processEager(eager)
with sd_lock:
characters = saveddata_session.query(Character).options(*eager).filter(Character.ownerID == lookfor).all()
characters = character_session.query(Character).options(*eager).filter(Character.ownerID == lookfor).all()
else:
raise TypeError("Need integer as argument")
return characters

View File

@@ -97,7 +97,7 @@ class Fit(object):
self.__mode = self.ship.validateModeItem(item)
else:
self.__mode = self.ship.validateModeItem(None)
self.__character = eos.db.saveddata.queries.getCharacter(self.characterID)
self.build()
def build(self):
@@ -166,6 +166,8 @@ class Fit(object):
@character.setter
def character(self, char):
self.__character = char
if char is not None:
self.characterID = char.ID
@property
def ship(self):