towerops/lib/towerops
Graham McIntire bb5766f1a6
Optimize list_agent_polling_targets to use SQL filtering
Rewrote list_agent_polling_targets/1 to filter equipment using SQL WHERE clause
instead of loading all SNMP-enabled equipment into memory and filtering in Elixir.

Previous implementation:
- Loaded ALL SNMP-enabled equipment with preloads (potentially 10,000+ records)
- Filtered in application code with equipment_matches_agent?/2 helper
- Called get_equipment_assignment/1 for each piece of equipment (N+1 queries)
- Memory-intensive and slow at scale

New implementation:
- Single SQL query with LEFT JOIN and compound WHERE clause
- Evaluates hierarchical assignment (equipment → site → organization) in SQL
- Only loads equipment assigned to the specific agent
- Scales efficiently to 10,000+ equipment

Performance improvement:
- With 10,000 equipment, 1000 assigned to agent:
  - Before: Load 10,000 records + 10,000 queries = massive memory + slow
  - After: Load 1,000 records in 1 query = 10x memory reduction + instant

Removed unused helper functions:
- equipment_matches_agent?/2
- site_matches_agent?/2

All 40 agent tests passing.
2026-01-15 07:33:52 -06:00
..
accounts add passkey 2026-01-09 12:26:32 -06:00
admin Add superuser system with user impersonation for admin support 2026-01-06 12:50:10 -06:00
agents Performance improvements: parallel polling and safer error handling 2026-01-14 19:04:32 -06:00
alerts more tests and logging around email 2026-01-06 16:00:41 -06:00
equipment Add database indexes and optimize SNMP polling 2026-01-15 07:28:14 -06:00
monitoring Refactor credo issues: reduce complexity and nesting depth 2026-01-06 13:55:16 -06:00
organizations add remote agent setup 2026-01-09 13:15:31 -06:00
proto protobufs 2026-01-09 17:33:01 -06:00
sites Implement hierarchical agent assignment for SNMP polling 2026-01-14 08:38:50 -06:00
snmp add MIB-based validation and generic profile tests 2026-01-08 08:57:21 -06:00
accounts.ex Streamline login flow and fix test failures 2026-01-13 13:08:24 -06:00
admin.ex Add superuser system with user impersonation for admin support 2026-01-06 12:50:10 -06:00
agents.ex Optimize list_agent_polling_targets to use SQL filtering 2026-01-15 07:33:52 -06:00
alerts.ex fix a few bits 2026-01-03 14:58:06 -06:00
application.ex event pubsub 2026-01-05 12:23:15 -06:00
equipment.ex Implement event logging system and fix sensor display 2026-01-05 10:42:34 -06:00
mailer.ex format 2025-12-21 11:31:08 -06:00
monitoring.ex Add TimescaleDB aggregate tests, implement on-demand calculation 2026-01-13 08:09:12 -06:00
organizations.ex fix dialyzer things 2026-01-03 12:56:40 -06:00
release.ex fix dialyzer things 2026-01-03 12:56:40 -06:00
repo.ex init 2025-12-21 11:10:43 -06:00
sites.ex 1. Sites Management 2025-12-21 13:39:19 -06:00
snmp.ex Add batch loading for sensor/interface stats to eliminate N+1 queries 2026-01-15 07:31:57 -06:00