Implement a character cache, as the database-layer cache is seemingly not working. =/

This commit is contained in:
blitzmann
2015-10-25 19:41:12 -04:00
parent 6496164d95
commit 781abeea53
6 changed files with 25 additions and 23 deletions

View File

@@ -21,11 +21,11 @@ from sqlalchemy import Table, Column, Integer, String, Boolean
from sqlalchemy.orm import mapper
from eos.db import saveddata_meta
from eos.types import Crest
from eos.types import CrestChar
crest_table = Table("crest", saveddata_meta,
Column("ID", Integer, primary_key = True),
Column("name", String, nullable = False, unique = True),
Column("refresh_token", String, nullable = False))
mapper(Crest, crest_table)
mapper(CrestChar, crest_table)

View File

@@ -19,7 +19,7 @@
from eos.db.util import processEager, processWhere
from eos.db import saveddata_session, sd_lock
from eos.types import User, Character, Fit, Price, DamagePattern, Fleet, MiscData, Wing, Squad, TargetResists, Crest
from eos.types import User, Character, Fit, Price, DamagePattern, Fleet, MiscData, Wing, Squad, TargetResists, CrestChar
from eos.db.saveddata.fleet import squadmembers_table
from eos.db.saveddata.fit import projectedFits_table
from sqlalchemy.sql import and_
@@ -419,23 +419,23 @@ def getProjectedFits(fitID):
def getCrestCharacters(eager=None):
eager = processEager(eager)
with sd_lock:
characters = saveddata_session.query(Crest).options(*eager).all()
characters = saveddata_session.query(CrestChar).options(*eager).all()
return characters
@cachedQuery(Crest, 1, "lookfor")
@cachedQuery(CrestChar, 1, "lookfor")
def getCrestCharacter(lookfor, eager=None):
if isinstance(lookfor, int):
if eager is None:
with sd_lock:
character = saveddata_session.query(Crest).get(lookfor)
character = saveddata_session.query(CrestChar).get(lookfor)
else:
eager = processEager(eager)
with sd_lock:
character = saveddata_session.query(Crest).options(*eager).filter(Crest.ID == lookfor).first()
character = saveddata_session.query(CrestChar).options(*eager).filter(CrestChar.ID == lookfor).first()
elif isinstance(lookfor, basestring):
eager = processEager(eager)
with sd_lock:
character = saveddata_session.query(Crest).options(*eager).filter(Crest.name == lookfor).first()
character = saveddata_session.query(CrestChar).options(*eager).filter(CrestChar.name == lookfor).first()
else:
raise TypeError("Need integer or string as argument")
return character