towerops/test/towerops_web
Graham McIntire 872f717dba Fix critical bugs, memory leaks, and N+1 queries (#132)
CRITICAL FIXES:
- Fix unsafe pattern matching in SNMP discovery that would crash on timeout
  - Changed {:ok, _} = ... to proper case statements with error handling
  - Extracted safe_discover/3 helper to reduce cyclomatic complexity
  - Added fallback to empty lists and warning logging for timeouts
  - Affects: discover_vlans, discover_ip_addresses, discover_processors, discover_storage

MEMORY LEAK FIXES (JS Hooks):
- GlobalSearchTrigger: Added destroyed() cleanup for click listener
- SidebarCollapse: Added destroyed() cleanup for click listener
- ThemeSelector: Added destroyed() cleanup for phx:set-theme window listener
- NetworkMap: Added destroyed() cleanup for 3 button listeners (zoom in/out/fit)
- All hooks now properly store handler references and remove listeners on unmount

LIVEVIEW FIXES:
- Added phx-update="ignore" to 5 SensorChart hooks to prevent chart re-initialization
- Added catch-all handle_info(_msg, socket) to 5 LiveViews to prevent crashes on unexpected messages
  - device_live/show.ex, device_live/index.ex, alert_live/index.ex, activity_feed_live.ex, agent_live/index.ex

N+1 QUERY FIXES:
- Created Gaiia.get_site_subscriber_summaries/1 batch function
- Refactored alert_live and device_live to use batch query instead of looping
- Reduces queries from N to 1 when loading site subscriber data

Impact:
- Prevents discovery worker crashes during SNMP timeouts
- Eliminates memory accumulation from leaked event handlers
- Prevents chart state loss on LiveView updates
- Prevents LiveView crashes from unexpected PubSub messages
- Improves database performance by eliminating N+1 queries in alert/device views
- Passes credo --strict with 0 issues

Reviewed-on: graham/towerops-web#132
2026-03-23 17:03:41 -05:00
..
channels Rewrite protobuf encoding/decoding in pure Gleam with integrated validation (#104) 2026-03-21 16:08:40 -05:00
components Fix footer positioning + add layout tests 2026-03-13 13:57:55 -05:00
controllers add auto ICMP ping check for all devices (#68) 2026-03-17 17:55:23 -05:00
graphql improve agent status display and fix two pre-existing test failures (#83) 2026-03-19 11:43:42 -05:00
helpers feat: add 12/24-hour time format setting with consistent timezone display 2026-02-13 15:16:29 -06:00
integration Merge remote-tracking branch 'origin/main' into feature/preseem-integration 2026-02-13 09:11:45 -06:00
live Fix critical bugs, memory leaks, and N+1 queries (#132) 2026-03-23 17:03:41 -05:00
plugs fix failing tests: ping check config and whitelist cache race (#55) 2026-03-17 08:11:36 -05:00
gleam_changelog_parser_test.exs Rewrite polling_offset, changelog_parser, and user_agent_parser in Gleam (#103) 2026-03-21 10:11:06 -05:00
graphql_socket_test.exs add mobile token auth to GraphQL endpoint (#48) 2026-03-16 15:23:07 -05:00
permissions_test.exs fix snmp v3 test 2026-02-06 10:21:54 -06:00
plug_exceptions_test.exs handle exceptions gracefully on api endpoints 2026-02-04 12:18:14 -06:00
remote_ip_test.exs perf: disable Req retry for faster error tests 2026-03-10 16:19:31 -05:00
telemetry_filter_test.exs Add GeoIP import HTTP tests 2026-03-10 16:02:49 -05:00
user_auth_test.exs perf(tests): remove/reduce Process.sleep calls for faster tests 2026-03-06 07:57:30 -06:00