Petits ajustements (cache => utils, noms de variables)
This commit is contained in:
+1
-1
@@ -7,8 +7,8 @@ from dash import Dash, Input, Output, State, dcc, html, page_container, page_reg
|
|||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from flask import Response
|
from flask import Response
|
||||||
|
|
||||||
from src.cache import cache
|
|
||||||
from src.utils import DEVELOPMENT
|
from src.utils import DEVELOPMENT
|
||||||
|
from utils.cache import cache
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ from dash import (
|
|||||||
register_page,
|
register_page,
|
||||||
)
|
)
|
||||||
|
|
||||||
from src.cache import cache
|
|
||||||
from src.db import query_marches, schema
|
from src.db import query_marches, schema
|
||||||
from src.figures import (
|
from src.figures import (
|
||||||
DataTable,
|
DataTable,
|
||||||
@@ -40,6 +39,7 @@ from src.utils.data import (
|
|||||||
from src.utils.frontend import get_enum_values_as_dict
|
from src.utils.frontend import get_enum_values_as_dict
|
||||||
from src.utils.seo import META_CONTENT
|
from src.utils.seo import META_CONTENT
|
||||||
from src.utils.table import COLUMNS, get_default_hidden_columns, prepare_table_data
|
from src.utils.table import COLUMNS, get_default_hidden_columns, prepare_table_data
|
||||||
|
from utils.cache import cache
|
||||||
|
|
||||||
NAME = "Observatoire"
|
NAME = "Observatoire"
|
||||||
|
|
||||||
@@ -658,9 +658,11 @@ def _normalize_filter_params(filter_params: dict) -> tuple:
|
|||||||
|
|
||||||
|
|
||||||
@cache.memoize()
|
@cache.memoize()
|
||||||
def _compute_dashboard_children(cache_key: tuple):
|
def _compute_dashboard_children(filter_params_normalized: tuple):
|
||||||
logger.debug("Cache miss — computing dashboard")
|
logger.debug("Cache miss — computing dashboard")
|
||||||
filter_params = {k: (list(v) if isinstance(v, tuple) else v) for k, v in cache_key}
|
filter_params = {
|
||||||
|
k: (list(v) if isinstance(v, tuple) else v) for k, v in filter_params_normalized
|
||||||
|
}
|
||||||
|
|
||||||
lff: pl.LazyFrame = query_marches().lazy()
|
lff: pl.LazyFrame = query_marches().lazy()
|
||||||
lff = prepare_dashboard_data(lff=lff, **filter_params)
|
lff = prepare_dashboard_data(lff=lff, **filter_params)
|
||||||
@@ -772,8 +774,8 @@ def update_dashboard_cards(*filter_values):
|
|||||||
):
|
):
|
||||||
filter_params[input_id] = value
|
filter_params[input_id] = value
|
||||||
|
|
||||||
cache_key = _normalize_filter_params(filter_params)
|
filter_params_normalized = _normalize_filter_params(filter_params)
|
||||||
children = _compute_dashboard_children(cache_key)
|
children = _compute_dashboard_children(filter_params_normalized)
|
||||||
|
|
||||||
return dbc.Row(children=children), filter_params
|
return dbc.Row(children=children), filter_params
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -5,12 +5,12 @@ import polars as pl
|
|||||||
from dash import no_update
|
from dash import no_update
|
||||||
from polars import selectors as cs
|
from polars import selectors as cs
|
||||||
|
|
||||||
from src.cache import cache
|
|
||||||
from src.db import query_marches, schema
|
from src.db import query_marches, schema
|
||||||
from src.utils import logger
|
from src.utils import logger
|
||||||
from src.utils.data import DATA_SCHEMA
|
from src.utils.data import DATA_SCHEMA
|
||||||
from src.utils.frontend import get_button_properties
|
from src.utils.frontend import get_button_properties
|
||||||
from src.utils.tracking import track_search
|
from src.utils.tracking import track_search
|
||||||
|
from utils.cache import cache
|
||||||
|
|
||||||
|
|
||||||
def split_filter_part(filter_part):
|
def split_filter_part(filter_part):
|
||||||
@@ -150,7 +150,7 @@ def dates_to_strings(lff: pl.LazyFrame, column: str) -> pl.LazyFrame:
|
|||||||
def normalize_sort_by(sort_by) -> tuple:
|
def normalize_sort_by(sort_by) -> tuple:
|
||||||
if not sort_by:
|
if not sort_by:
|
||||||
return ()
|
return ()
|
||||||
return tuple((entry["column_id"], entry["direction"]) for entry in sort_by)
|
return tuple(sorted((entry["column_id"], entry["direction"]) for entry in sort_by))
|
||||||
|
|
||||||
|
|
||||||
def format_number(number) -> str:
|
def format_number(number) -> str:
|
||||||
@@ -167,7 +167,7 @@ def unformat_montant(number: str) -> float:
|
|||||||
|
|
||||||
|
|
||||||
def format_values(dff: pl.DataFrame) -> pl.DataFrame:
|
def format_values(dff: pl.DataFrame) -> pl.DataFrame:
|
||||||
def format_montant(expr, scale=None):
|
def format_montant(expr):
|
||||||
# https://stackoverflow.com/a/78636786
|
# https://stackoverflow.com/a/78636786
|
||||||
expr = expr.cast(pl.String)
|
expr = expr.cast(pl.String)
|
||||||
expr = expr.str.splitn(".", 2)
|
expr = expr.str.splitn(".", 2)
|
||||||
|
|||||||
+2
-2
@@ -85,7 +85,7 @@ def flask_app():
|
|||||||
"""Minimal Flask app with SimpleCache so @cache.memoize() works in tests."""
|
"""Minimal Flask app with SimpleCache so @cache.memoize() works in tests."""
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
|
|
||||||
from src.cache import cache
|
from utils.cache import cache
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
cache.init_app(app, config={"CACHE_TYPE": "SimpleCache"})
|
cache.init_app(app, config={"CACHE_TYPE": "SimpleCache"})
|
||||||
@@ -97,7 +97,7 @@ def reset_cache(flask_app):
|
|||||||
"""Ensure the flask-caching backend is empty between tests so that
|
"""Ensure the flask-caching backend is empty between tests so that
|
||||||
cache-hit assertions are meaningful. Falls back to no-op when no
|
cache-hit assertions are meaningful. Falls back to no-op when no
|
||||||
Flask app context is active (NullCache)."""
|
Flask app context is active (NullCache)."""
|
||||||
from src.cache import cache
|
from utils.cache import cache
|
||||||
|
|
||||||
with flask_app.app_context():
|
with flask_app.app_context():
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user