towerops/lib/towerops_web/plugs
Graham McIntire 701ce12f08 perf+refactor: codebase-wide query and antipattern audit
Performance:
- schedule_live: preload page once instead of get_schedule!/1 per row
- alert_live + alerts: DB-side status filter; Repo.aggregate counts replace length/Enum.count over 500-row fetches on every event
- dashboard_live: drop duplicate get_device_status_counts; cap active alerts to 20 + use count_active_alerts/1
- maintenance.active_windows_for_device: 3 round-trips collapsed into one query (per-site-id branch keeps Postgres parameter types unambiguous)
- sites.build_site_tree: O(N^2) -> O(N) via group_by(parent_site_id)
- accounts.sole_owner_organizations: single group_by + having instead of per-org Repo.aggregate loop
- agents + agent_live (org + admin): count_assigned_devices_batch/1 + count_agent_polling_targets/1 (no preloads)
- alert_digest_worker: list_alerts_by_ids/1 batches digest fetch
- gaiia: distinct: true at DB; limit 50 on bidirectional ilike

Indexes:
- maintenance_windows(organization_id, starts_at, ends_at) WHERE suppress_alerts = true
- alerts(check_id) WHERE resolved_at IS NULL

Antipatterns:
- agents.delete_agent_token: PubSub.broadcast moved outside Repo.transaction so a rollback no longer leaves subscribers acting on a non-existent deletion
- integrations_controller.to_atom_keys: replaced String.to_existing_atom on user-controlled JSON keys with explicit allowlist
- 9 Task.start callsites converted to Task.Supervisor.start_child(Towerops.TaskSupervisor, ...) so background DB writes survive shutdown (test-mode discovery shims left as-is for sandbox semantics)
2026-04-28 16:58:51 -05:00
..
api_auth.ex refactor: use API token auth for profile imports instead of session cookies 2026-01-18 09:30:21 -06:00
brute_force_protection.ex test: improve test coverage and code quality 2026-03-15 14:49:55 -05:00
capture_timezone.ex Use detected timezone from session in user registration 2026-02-01 12:18:33 -06:00
check_policy_consent.ex gdpr consent tracking 2026-01-29 11:12:35 -06:00
detect_eu_user.ex perf: disable Req retry for faster error tests 2026-03-10 16:19:31 -05:00
filter_noisy_logs.ex fix: properly disable Plug.Telemetry logging for health checks 2026-03-08 16:39:26 -05:00
graphql_auth.ex perf+refactor: codebase-wide query and antipattern audit 2026-04-28 16:58:51 -05:00
graphql_introspection.ex Security fixes: mask credentials in logs/API, fix cookie/CSP/LIKE injection/webhooks 2026-02-15 09:09:04 -06:00
markdown_negotiation.ex fix: correct login URL path in markdown negotiation content 2026-04-17 15:50:31 -05:00
mobile_auth.ex perf+refactor: codebase-wide query and antipattern audit 2026-04-28 16:58:51 -05:00
rate_limit.ex chore: rate_limit rewrite + on-call redesign plan + handoff_notifications_mode 2026-04-28 12:17:29 -05:00
remote_ip_logger.ex perf: disable Req retry for faster error tests 2026-03-10 16:19:31 -05:00
security_headers.ex fix: allow data URLs in CSP for dynamic favicon 2026-03-06 13:51:31 -06:00
update_session_activity.ex perf+refactor: codebase-wide query and antipattern audit 2026-04-28 16:58:51 -05:00
webhook_auth.ex Add CI-triggered mass agent update webhook 2026-02-10 13:40:32 -06:00