towerops/lib/towerops_web/controllers/api/v1
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
..
activity_controller.ex feat: expand REST API with alerts, agents, org settings, members, integrations, metrics, activity endpoints 2026-02-14 11:28:57 -06:00
agent_release_webhook_controller.ex tests: raise coverage to 70% via helper promotion + new unit/property tests 2026-04-24 09:49:06 -05:00
agents_controller.ex fix: resolve compilation errors, test failures, and credo issues 2026-02-14 12:23:10 -06:00
alerts_controller.ex fix: resolve compilation errors, test failures, and credo issues 2026-02-14 12:23:10 -06:00
check_results_controller.ex reliability-audit-fixes (#181) 2026-03-26 14:10:36 -05:00
checks_controller.ex dialyzer: fix all unmatched_return warnings (154 → 0) 2026-04-21 10:03:55 -05:00
devices_controller.ex dialyzer: fix all unmatched_return warnings (154 → 0) 2026-04-21 10:03:55 -05:00
escalation_policies_controller.ex feat: add REST API and GraphQL for on-call schedules and escalation policies 2026-03-11 14:01:15 -05:00
gaiia_webhook_controller.ex fix/findings-medium-priority (#188) 2026-03-27 12:31:53 -05:00
geoip_controller.ex dialyzer: fix remaining 88 warnings — clean dialyzer run 2026-04-21 10:32:42 -05:00
integrations_controller.ex perf+refactor: codebase-wide query and antipattern audit 2026-04-28 16:58:51 -05:00
invitations_controller.ex fix: resolve compilation errors, test failures, and credo issues 2026-02-14 12:23:10 -06:00
maintenance_windows_controller.ex add maintenance windows REST API and GraphQL support 2026-03-11 14:33:25 -05:00
members_controller.ex fix: resolve compilation errors, test failures, and credo issues 2026-02-14 12:23:10 -06:00
mib_controller.ex dialyzer: fix all unmatched_return warnings (154 → 0) 2026-04-21 10:03:55 -05:00
organization_controller.ex fix: use correct auth check for API organization updates 2026-03-10 13:41:38 -05:00
pagerduty_webhook_controller.ex reliability-audit-fixes (#181) 2026-03-26 14:10:36 -05:00
schedules_controller.ex feat: add REST API and GraphQL for on-call schedules and escalation policies 2026-03-11 14:01:15 -05:00
sites_controller.ex Refactor duplicate site API logic 2026-03-10 16:27:35 -05:00
stripe_webhook_controller.ex reliability-audit-fixes (#181) 2026-03-26 14:10:36 -05:00