New alert service
This commit is contained in:
@@ -14,6 +14,7 @@ from shared.routing import RouteBuilder
|
||||
from app.services.production_service import ProductionService
|
||||
from app.schemas.production import ProductionDashboardSummary
|
||||
from app.core.config import settings
|
||||
from app.utils.cache import get_cached, set_cached, make_cache_key
|
||||
|
||||
logger = structlog.get_logger()
|
||||
route_builder = RouteBuilder('production')
|
||||
@@ -35,10 +36,22 @@ async def get_dashboard_summary(
|
||||
current_user: dict = Depends(get_current_user_dep),
|
||||
production_service: ProductionService = Depends(get_production_service)
|
||||
):
|
||||
"""Get production dashboard summary"""
|
||||
"""Get production dashboard summary with caching (60s TTL)"""
|
||||
try:
|
||||
# PHASE 2: Check cache first
|
||||
cache_key = make_cache_key("production_dashboard", str(tenant_id))
|
||||
cached_result = await get_cached(cache_key)
|
||||
if cached_result is not None:
|
||||
logger.debug("Cache hit for production dashboard", cache_key=cache_key, tenant_id=str(tenant_id))
|
||||
return ProductionDashboardSummary(**cached_result)
|
||||
|
||||
# Cache miss - fetch from database
|
||||
summary = await production_service.get_dashboard_summary(tenant_id)
|
||||
|
||||
# PHASE 2: Cache the result (60s TTL for production batches)
|
||||
await set_cached(cache_key, summary.model_dump(), ttl=60)
|
||||
logger.debug("Cached production dashboard", cache_key=cache_key, ttl=60, tenant_id=str(tenant_id))
|
||||
|
||||
logger.info("Retrieved production dashboard summary",
|
||||
tenant_id=str(tenant_id))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user