Skip to content
Snippets Groups Projects
Commit d35e2e24 authored by Martin Mareš's avatar Martin Mareš
Browse files

Kešování get_root_place()

parent 41c48802
Branches
No related tags found
No related merge requests found
...@@ -117,8 +117,15 @@ class Place(Base): ...@@ -117,8 +117,15 @@ class Place(Base):
return len(PlaceType.choices(level=self.level + 1)) > 0 return len(PlaceType.choices(level=self.level + 1)) > 0
# Předpokládáme, že za běhu aplikace se root nezmění
root_place_cache: Optional[Place] = None
def get_root_place(): def get_root_place():
return get_session().query(Place).filter_by(parent=None).one() global root_place_cache
if root_place_cache is None:
root_place_cache = get_session().query(Place).filter_by(parent=None).one()
return root_place_cache
def get_place_by_code(code: str, fetch_school: bool = False) -> Optional[Place]: def get_place_by_code(code: str, fetch_school: bool = False) -> Optional[Place]:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment