06/04 Optimize app

This commit is contained in:
2026-06-04 14:28:35 -04:00
parent 0190da30d4
commit 3f2e83ce2d
5 changed files with 44 additions and 5 deletions
+21 -1
View File
@@ -1073,7 +1073,24 @@ def get_user_active_shifts(user_id: int):
# ─── Admin Dashboard ──────────────────────────────────────────────────────────
_admin_stats_cache: dict | None = None
_admin_stats_cached_at: datetime.datetime | None = None
_ADMIN_STATS_TTL_S = 60 # seconds
def invalidate_admin_stats_cache():
global _admin_stats_cache, _admin_stats_cached_at
_admin_stats_cache = None
_admin_stats_cached_at = None
def get_admin_dashboard_stats():
global _admin_stats_cache, _admin_stats_cached_at
now = datetime.datetime.now()
if (_admin_stats_cache is not None and _admin_stats_cached_at is not None
and (now - _admin_stats_cached_at).total_seconds() < _ADMIN_STATS_TTL_S):
return _admin_stats_cache
conn = None
try:
conn = get_connection()
@@ -1123,7 +1140,7 @@ def get_admin_dashboard_stats():
)
ai_analyses_30d = cur.fetchone()["n"]
cur.close()
return {
result = {
"user_stats": user_stats,
"total_sites": total_sites,
"total_users": total_users,
@@ -1132,6 +1149,9 @@ def get_admin_dashboard_stats():
"bids_due_soon": bids_due_soon,
"ai_analyses_30d": ai_analyses_30d,
}
_admin_stats_cache = result
_admin_stats_cached_at = now
return result
finally:
if conn:
conn.close()