Aug 27 - Add MySQL optimize and security check

This commit is contained in:
2026-08-27 17:36:28 -04:00
parent ba10ec42e0
commit b7bc0f0335
16 changed files with 1524 additions and 58 deletions
+14 -4
View File
@@ -17,6 +17,16 @@ bp = Blueprint('dashboard', __name__)
logger = logging.getLogger(__name__)
# Columns the dashboard actually reads off an issue row. The cards below need
# counts and buckets, never a hydrated Issue — loading the full entity pulls the
# description TEXT and three JSON photo columns for every open issue in scope,
# on every dashboard load, and registers each one in the identity map.
# A Row exposes the same attribute names, so _handler_split() and sla_status()
# work against these unchanged.
_ISSUE_CARD_COLS = (Issue.id, Issue.severity, Issue.status,
Issue.reported_at, Issue.handler_type)
def _handler_split(issues):
"""Count a list of Issues by handler_type (phase35). Rows default to
'internal' when unset. Returns a dict keyed internal/facility/vendor."""
@@ -102,7 +112,7 @@ def index():
))
# Single query — derive count from the list to avoid hitting the DB twice
open_issues_all = open_issues_q.all()
open_issues_all = open_issues_q.with_entities(*_ISSUE_CARD_COLS).all()
open_issues = len(open_issues_all)
severity_breakdown = {
'critical': sum(1 for i in open_issues_all if i.severity == 'critical'),
@@ -224,7 +234,7 @@ def index():
elif is_customer and not customer_facility_ids:
all_open_issues = []
else:
all_open_issues = sla_q.all()
all_open_issues = sla_q.with_entities(*_ISSUE_CARD_COLS).all()
sla_breached = sum(1 for i in all_open_issues if sla_status(i) == 'breached')
sla_at_risk = sum(1 for i in all_open_issues if sla_status(i) == 'at_risk')
@@ -250,7 +260,7 @@ def index():
Issue.facility_id.in_(customer_facility_ids),
_AreaT.facility_id.in_(customer_facility_ids),
))
opened_today_all = opened_today_q.all()
opened_today_all = opened_today_q.with_entities(*_ISSUE_CARD_COLS).all()
issues_opened_today = len(opened_today_all)
opened_today_handler = _handler_split(opened_today_all)
@@ -331,7 +341,7 @@ def index():
))
elif is_customer:
unassigned_q = unassigned_q.filter(False) # not relevant for customers
unassigned_all = unassigned_q.all()
unassigned_all = unassigned_q.with_entities(*_ISSUE_CARD_COLS).all()
unassigned_open = len(unassigned_all)
unassigned_handler = _handler_split(unassigned_all)