towerops/lib/towerops/workers
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
..
agent_latency_evaluator.ex fix: cloud poller automatic rebalancing 2026-02-12 15:32:33 -06:00
alert_digest_worker.ex perf+refactor: codebase-wide query and antipattern audit 2026-04-28 16:58:51 -05:00
alert_notification_worker.ex dialyzer: fix remaining 88 warnings — clean dialyzer run 2026-04-21 10:32:42 -05:00
backup_summary_worker.ex Add strict typespecs to all Oban worker perform/1 functions 2026-02-06 09:50:51 -06:00
backup_timeout_worker.ex Add strict typespecs to all Oban worker perform/1 functions 2026-02-06 09:50:51 -06:00
billing_sync_worker.ex stripe and email after signup 2026-03-06 10:07:27 -06:00
capacity_insight_worker.ex reliability-audit-fixes (#181) 2026-03-26 14:10:36 -05:00
check_executor_worker.ex dialyzer: fix all unmatched_return warnings (154 → 0) 2026-04-21 10:03:55 -05:00
check_worker.ex tests: raise coverage to 70% via helper promotion + new unit/property tests 2026-04-24 09:49:06 -05:00
cloud_latency_probe_worker.ex dialyzer: fix all unmatched_return warnings (154 → 0) 2026-04-21 10:03:55 -05:00
cloudflare_ban_worker.ex Add 404-based brute force protection system 2026-02-10 16:31:48 -06:00
cn_maestro_sync_worker.ex refactor: convert 6 Gleam modules to idiomatic Elixir with TDD (#196) 2026-03-28 09:52:07 -05:00
data_retention_worker.ex feat: add per-organization data retention with 1-year default (#144) 2026-03-24 15:30:43 -05:00
device_health_insight_worker.ex feat: command center dashboard with unified insights and contextual enrichment 2026-02-13 14:52:49 -06:00
device_monitor_worker.ex dialyzer: fix all unmatched_return warnings (154 → 0) 2026-04-21 10:03:55 -05:00
device_poller_worker.ex tests: raise coverage to 70% via helper promotion + new unit/property tests 2026-04-24 09:49:06 -05:00
discovery_worker.ex dialyzer: fix all unmatched_return warnings (154 → 0) 2026-04-21 10:03:55 -05:00
escalation_check_worker.ex dialyzer: fix all unmatched_return warnings (154 → 0) 2026-04-21 10:03:55 -05:00
expired_ban_cleanup_worker.ex Add 404-based brute force protection system 2026-02-10 16:31:48 -06:00
firmware_version_fetcher_worker.ex Add GeoIP import HTTP tests 2026-03-10 16:02:49 -05:00
gaiia_insight_worker.ex dialyzer: fix all unmatched_return warnings (154 → 0) 2026-04-21 10:03:55 -05:00
gaiia_sync_worker.ex add gaiia integration stages 1-2: sync engine and entity mapping UI 2026-02-13 10:31:32 -06:00
job_cleanup_task.ex Skip Phoenix poller/monitor scheduling when SNMP disabled 2026-02-17 07:12:15 -06:00
job_health_check_worker.ex fix: dns and ping checks not executing in production (#71) 2026-03-18 08:43:37 -05:00
login_history_cleanup_worker.ex Add strict typespecs to all Oban worker perform/1 functions 2026-02-06 09:50:51 -06:00
mikrotik_backup_worker.ex dialyzer: fix all unmatched_return warnings (154 → 0) 2026-04-21 10:03:55 -05:00
netbox_sync_worker.ex tests: raise coverage to 70% via helper promotion + new unit/property tests 2026-04-24 09:49:06 -05:00
polling_offset.ex refactor: convert 6 Gleam modules to idiomatic Elixir with TDD (#196) 2026-03-28 09:52:07 -05:00
preseem_baseline_worker.ex add preseem insights schema, generation, and queries 2026-02-13 08:53:01 -06:00
preseem_sync_worker.ex refactor: convert 6 Gleam modules to idiomatic Elixir with TDD (#196) 2026-03-28 09:52:07 -05:00
report_worker.ex reliability-audit-fixes (#181) 2026-03-26 14:10:36 -05:00
session_cleanup_worker.ex Add strict typespecs to all Oban worker perform/1 functions 2026-02-06 09:50:51 -06:00
sonar_sync_worker.ex tests: raise coverage to 70% via helper promotion + new unit/property tests 2026-04-24 09:49:06 -05:00
splynx_sync_worker.ex tests: raise coverage to 70% via helper promotion + new unit/property tests 2026-04-24 09:49:06 -05:00
stale_agent_worker.ex Add comprehensive typespecs to agent-related modules 2026-02-06 09:33:44 -06:00
stale_violation_cleanup_worker.ex Add 404-based brute force protection system 2026-02-10 16:31:48 -06:00
system_insight_worker.ex fix/findings-medium-priority (#188) 2026-03-27 12:31:53 -05:00
uisp_sync_worker.ex tests: raise coverage to 70% via helper promotion + new unit/property tests 2026-04-24 09:49:06 -05:00
visp_sync_worker.ex tests: raise coverage to 70% via helper promotion + new unit/property tests 2026-04-24 09:49:06 -05:00
weather_sync_worker.ex dialyzer: fix all unmatched_return warnings (154 → 0) 2026-04-21 10:03:55 -05:00
welcome_email_worker.ex dialyzer: fix all unmatched_return warnings (154 → 0) 2026-04-21 10:03:55 -05:00
wireless_insight_worker.ex reliability-audit-fixes (#181) 2026-03-26 14:10:36 -05:00