mirror of
https://github.com/fhswf/aki_prj23_transparenzregister.git
synced 2025-06-22 17:53:55 +02:00
Experimental caching (#285)
Added some caching decoraterors to speedup page delivery.
This commit is contained in:
@ -65,6 +65,10 @@ def get_finance_data(session: Session) -> pd.DataFrame:
|
||||
return pd.read_sql(str(query_finance), engine)
|
||||
|
||||
|
||||
@cached( # type: ignore
|
||||
cache=TTLCache(maxsize=100, ttl=600),
|
||||
key=lambda session, company_id: hash((company_id, str(session.bind))),
|
||||
)
|
||||
def get_finance_data_of_one_company(session: Session, company_id: int) -> pd.DataFrame:
|
||||
"""Collects all available finance data of one company.
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
"""Header elements for Dash."""
|
||||
|
||||
from cachetools import TTLCache, cached
|
||||
from dash import dcc, html
|
||||
|
||||
|
||||
def create_header(options: dict) -> html:
|
||||
def create_header(options: dict[int, str]) -> html:
|
||||
"""Creates header for dashboard.
|
||||
|
||||
Args:
|
||||
@ -51,7 +51,10 @@ def create_header(options: dict) -> html:
|
||||
)
|
||||
|
||||
|
||||
def create_selection_header(selected_name: str) -> html:
|
||||
@cached(
|
||||
cache=TTLCache(maxsize=100, ttl=600), key=lambda selected_name: hash(selected_name) # type: ignore
|
||||
)
|
||||
def create_selection_header(selected_name: str) -> html.Div:
|
||||
"""Create company header based on selected company.
|
||||
|
||||
Args:
|
||||
|
@ -1,5 +1,6 @@
|
||||
"""Company detail page."""
|
||||
import dash
|
||||
from cachetools import TTLCache, cached
|
||||
from dash import html
|
||||
|
||||
from aki_prj23_transparenzregister.ui import (
|
||||
@ -14,6 +15,7 @@ dash.register_page(
|
||||
)
|
||||
|
||||
|
||||
@cached(cache=TTLCache(maxsize=100, ttl=600), key=lambda value: hash(value)) # type: ignore
|
||||
def layout(value: str = "1") -> html:
|
||||
"""Defines the layout of the company page.
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
"""Person detail page."""
|
||||
import dash
|
||||
from cachetools import TTLCache, cached
|
||||
from dash import html
|
||||
|
||||
from aki_prj23_transparenzregister.ui import data_elements, header_elements
|
||||
@ -10,7 +11,8 @@ dash.register_page(
|
||||
)
|
||||
|
||||
|
||||
def layout(value: str = "1") -> html:
|
||||
@cached(cache=TTLCache(maxsize=100, ttl=60), key=lambda value: hash(value)) # type: ignore
|
||||
def layout(value: str = "1") -> html.Div:
|
||||
"""Defines the layout of the person detail page.
|
||||
|
||||
Args:
|
||||
@ -27,9 +29,5 @@ def layout(value: str = "1") -> html:
|
||||
person_id = int(value)
|
||||
# get all necessary data of the selected person
|
||||
selected_person_stats = data_elements.get_person_data(session).loc[person_id]
|
||||
selected_person_name = (
|
||||
selected_person_stats["person_firstname"]
|
||||
+ " "
|
||||
+ selected_person_stats["person_lastname"]
|
||||
)
|
||||
selected_person_name = f"{selected_person_stats['person_firstname']} {selected_person_stats['person_lastname']}"
|
||||
return header_elements.create_selection_header(selected_person_name)
|
||||
|
Reference in New Issue
Block a user