mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-11 21:40:17 +02:00
Cache related objects to speed queries (#616)
This commit is contained in:
parent
e1ccd972e4
commit
c4a6492ab5
@ -41,16 +41,22 @@ class Corporation(Entity):
|
|||||||
self.ceo_id = ceo_id
|
self.ceo_id = ceo_id
|
||||||
self.members = members
|
self.members = members
|
||||||
self.alliance_id = alliance_id
|
self.alliance_id = alliance_id
|
||||||
|
self._alliance = None
|
||||||
|
self._ceo = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def alliance(self):
|
def alliance(self):
|
||||||
if self.alliance_id:
|
if self.alliance_id:
|
||||||
return self.provider.get_alliance(self.alliance_id)
|
if not self._alliance:
|
||||||
|
self._alliance = self.provider.get_alliance(self.alliance_id)
|
||||||
|
return self._alliance
|
||||||
return Entity(None, None)
|
return Entity(None, None)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ceo(self):
|
def ceo(self):
|
||||||
return self.provider.get_character(self.ceo_id)
|
if not self._ceo:
|
||||||
|
self._ceo = self.provider.get_character(self.ceo_id)
|
||||||
|
return self._ceo
|
||||||
|
|
||||||
|
|
||||||
class Alliance(Entity):
|
class Alliance(Entity):
|
||||||
@ -60,10 +66,14 @@ class Alliance(Entity):
|
|||||||
self.ticker = ticker
|
self.ticker = ticker
|
||||||
self.corp_ids = corp_ids
|
self.corp_ids = corp_ids
|
||||||
self.executor_corp_id = executor_corp_id
|
self.executor_corp_id = executor_corp_id
|
||||||
|
self._corps = {}
|
||||||
|
|
||||||
def corp(self, id):
|
def corp(self, id):
|
||||||
assert id in self.corp_ids
|
assert id in self.corp_ids
|
||||||
return self.provider.get_corp(id)
|
if not id in self._corps:
|
||||||
|
self._corps[id] = self.provider.get_corp(id)
|
||||||
|
self._corps[id]._alliance = self
|
||||||
|
return self._corps[id]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def corps(self):
|
def corps(self):
|
||||||
@ -71,7 +81,7 @@ class Alliance(Entity):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def executor_corp(self):
|
def executor_corp(self):
|
||||||
return self.provider.get_corp(self.executor_corp_id)
|
return self.corp(self.executor_corp_id)
|
||||||
|
|
||||||
|
|
||||||
class Character(Entity):
|
class Character(Entity):
|
||||||
@ -80,15 +90,19 @@ class Character(Entity):
|
|||||||
self.provider = provider
|
self.provider = provider
|
||||||
self.corp_id = corp_id
|
self.corp_id = corp_id
|
||||||
self.alliance_id = alliance_id
|
self.alliance_id = alliance_id
|
||||||
|
self._corp = None
|
||||||
|
self._alliance = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def corp(self):
|
def corp(self):
|
||||||
return self.provider.get_corp(self.corp_id)
|
if not self._corp:
|
||||||
|
self._corp = self.provider.get_corp(self.corp_id)
|
||||||
|
return self._corp
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def alliance(self):
|
def alliance(self):
|
||||||
if self.alliance_id:
|
if self.alliance_id:
|
||||||
return self.provider.get_alliance(self.alliance_id)
|
return self.corp.alliance
|
||||||
return Entity(None, None)
|
return Entity(None, None)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user