diff --git a/_db.py b/_db.py index fc3e09b..3c6d5ec 100644 --- a/_db.py +++ b/_db.py @@ -16,6 +16,6 @@ real connection opens only when a query actually executes. """ from __future__ import annotations -from app.db.mariadb import run_select_query # noqa: F401 (kernel SELECT-only proxy) +from app.db.mariadb import run_select_query, cached_select # noqa: F401 (kernel read proxies) -__all__ = ["run_select_query"] +__all__ = ["run_select_query", "cached_select"] diff --git a/api/routes.py b/api/routes.py index 57733fd..7a20c46 100644 --- a/api/routes.py +++ b/api/routes.py @@ -46,7 +46,7 @@ from typing import Any, Optional from fastapi import APIRouter, Query -from .._db import run_select_query +from .._db import run_select_query, cached_select logger = logging.getLogger(__name__) @@ -128,8 +128,11 @@ def _group_carts(rows: list[dict[str, Any]], colors: dict[str, int]) -> "dict[st def _fetch_presses(plant: str) -> list[str]: + # Reference data (admin-edited), re-read on every 12s poll — served from the shared + # reference cache so it stops consuming a pool checkout each poll. try: - rows = run_select_query( + rows = cached_select( + f"tov:presses:{plant}", "SELECT psPress AS press FROM press_settings.presses WHERE psPlant = :plant " "ORDER BY CAST(psPress AS UNSIGNED), psPress", {"plant": plant}, @@ -239,8 +242,10 @@ def _fetch_downtime_reasons(plant: str) -> dict[str, int]: def _fetch_reason_texts() -> dict[int, str]: + # Reference data (admin-edited), full-table read on every poll — served from cache. try: - rows = run_select_query( + rows = cached_select( + "tov:reason_texts", "SELECT id, reason_DE AS de FROM settings.downtime_reasons", {} ) except Exception as e: # noqa: BLE001