Fix remaining nesting depth issues

Extracts nested logic into helper functions to comply with Credo
requirements (max nesting depth 2):

- data_builder.ex: Extract historical packet data building
  (build_historical_packet_data/2)
  Reduces depth 3 -> depth 2

- streaming_packets_pubsub.ex: Extract subscriber filtering and messaging
  (send_to_matching_subscribers/5)
  Removes conditional check by sending cleanup message unconditionally
  (GenServer handles empty list gracefully)
  Reduces depth 3 -> depth 2

- historical_loader.ex: Extract RF path station loading logic
  (maybe_load_rf_path_stations/3)
  Reduces depth 3 -> depth 2

- packet_processor.ex: Extract marker popup logic
  (send_marker_with_popup_check/2)
  Reduces depth 3 -> depth 2

Fixes all 4 remaining Credo nesting depth issues.
All nesting depth issues now resolved (0 remaining).
This commit is contained in:
Graham McIntire 2026-02-09 12:37:38 -06:00
parent 318eb30046
commit 41000e3482
No known key found for this signature in database
4 changed files with 39 additions and 28 deletions

View file

@ -119,17 +119,7 @@ defmodule Aprsme.StreamingPacketsPubSub do
server_pid = self()
Aprsme.BroadcastTaskSupervisor.async_execute(fn ->
dead_pids =
subscribers
|> Stream.filter(fn {_pid, bounds} -> packet_in_bounds?(lat, lon, bounds) end)
|> Enum.reduce([], fn {pid, _bounds}, acc ->
send_to_subscriber_if_alive(pid, packet, acc)
end)
# Send dead pids back to GenServer for cleanup
if dead_pids != [] do
send(server_pid, {:cleanup_dead_subscribers, dead_pids})
end
send_to_matching_subscribers(subscribers, lat, lon, packet, server_pid)
end)
end
@ -182,6 +172,18 @@ defmodule Aprsme.StreamingPacketsPubSub do
lat_in_bounds and lon_in_bounds
end
defp send_to_matching_subscribers(subscribers, lat, lon, packet, server_pid) do
dead_pids =
subscribers
|> Stream.filter(fn {_pid, bounds} -> packet_in_bounds?(lat, lon, bounds) end)
|> Enum.reduce([], fn {pid, _bounds}, acc ->
send_to_subscriber_if_alive(pid, packet, acc)
end)
# Send dead pids back to GenServer for cleanup
send(server_pid, {:cleanup_dead_subscribers, dead_pids})
end
defp send_to_subscriber_if_alive(pid, packet, acc) do
if Process.alive?(pid) do
send(pid, {:streaming_packet, packet})

View file

@ -184,10 +184,7 @@ defmodule AprsmeWeb.MapLive.DataBuilder do
filter_historical_by_distance(historical, most_recent_lat, most_recent_lon)
# Build data for remaining historical packets
historical_data =
filtered_historical
|> Enum.map(fn packet -> build_minimal_packet_data(packet, false, has_weather) end)
|> Enum.filter(& &1)
historical_data = build_historical_packet_data(filtered_historical, has_weather)
# Combine most recent and filtered historical
Enum.filter([most_recent_data | historical_data], & &1)
@ -628,4 +625,10 @@ defmodule AprsmeWeb.MapLive.DataBuilder do
false
end
end
defp build_historical_packet_data(filtered_historical, has_weather) do
filtered_historical
|> Enum.map(fn packet -> build_minimal_packet_data(packet, false, has_weather) end)
|> Enum.filter(& &1)
end
end

View file

@ -197,12 +197,7 @@ defmodule AprsmeWeb.MapLive.HistoricalLoader do
end
# If tracking a callsign and this is the first batch, also load RF path stations
socket =
if socket.assigns.tracked_callsign != "" and batch_offset == 0 do
load_rf_path_stations(socket, historical_packets)
else
socket
end
socket = maybe_load_rf_path_stations(socket, batch_offset, historical_packets)
process_loaded_packets(socket, historical_packets, packet_data_list, batch_offset)
else
@ -424,6 +419,14 @@ defmodule AprsmeWeb.MapLive.HistoricalLoader do
socket
end
defp maybe_load_rf_path_stations(socket, batch_offset, historical_packets) do
if socket.assigns.tracked_callsign != "" and batch_offset == 0 do
load_rf_path_stations(socket, historical_packets)
else
socket
end
end
defp load_rf_path_stations(socket, packets) do
# Extract unique RF path stations from all packets
rf_path_stations =

View file

@ -109,13 +109,7 @@ defmodule AprsmeWeb.MapLive.PacketProcessor do
marker_data = PacketUtils.build_packet_data(packet, true, get_locale(socket))
if marker_data do
# Only show new packet popup if no station popup is currently open
if socket.assigns.station_popup_open do
# Send without opening popup to avoid interrupting user
LiveView.push_event(socket, "new_packet", Map.put(marker_data, :openPopup, false))
else
LiveView.push_event(socket, "new_packet", marker_data)
end
send_marker_with_popup_check(socket, marker_data)
else
socket
end
@ -167,4 +161,13 @@ defmodule AprsmeWeb.MapLive.PacketProcessor do
# This function should be moved to DisplayManager module
socket
end
defp send_marker_with_popup_check(socket, marker_data) do
if socket.assigns.station_popup_open do
# Send without opening popup to avoid interrupting user
LiveView.push_event(socket, "new_packet", Map.put(marker_data, :openPopup, false))
else
LiveView.push_event(socket, "new_packet", marker_data)
end
end
end