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:
parent
318eb30046
commit
41000e3482
4 changed files with 39 additions and 28 deletions
|
|
@ -119,17 +119,7 @@ defmodule Aprsme.StreamingPacketsPubSub do
|
||||||
server_pid = self()
|
server_pid = self()
|
||||||
|
|
||||||
Aprsme.BroadcastTaskSupervisor.async_execute(fn ->
|
Aprsme.BroadcastTaskSupervisor.async_execute(fn ->
|
||||||
dead_pids =
|
send_to_matching_subscribers(subscribers, lat, lon, packet, server_pid)
|
||||||
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
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -182,6 +172,18 @@ defmodule Aprsme.StreamingPacketsPubSub do
|
||||||
lat_in_bounds and lon_in_bounds
|
lat_in_bounds and lon_in_bounds
|
||||||
end
|
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
|
defp send_to_subscriber_if_alive(pid, packet, acc) do
|
||||||
if Process.alive?(pid) do
|
if Process.alive?(pid) do
|
||||||
send(pid, {:streaming_packet, packet})
|
send(pid, {:streaming_packet, packet})
|
||||||
|
|
|
||||||
|
|
@ -184,10 +184,7 @@ defmodule AprsmeWeb.MapLive.DataBuilder do
|
||||||
filter_historical_by_distance(historical, most_recent_lat, most_recent_lon)
|
filter_historical_by_distance(historical, most_recent_lat, most_recent_lon)
|
||||||
|
|
||||||
# Build data for remaining historical packets
|
# Build data for remaining historical packets
|
||||||
historical_data =
|
historical_data = build_historical_packet_data(filtered_historical, has_weather)
|
||||||
filtered_historical
|
|
||||||
|> Enum.map(fn packet -> build_minimal_packet_data(packet, false, has_weather) end)
|
|
||||||
|> Enum.filter(& &1)
|
|
||||||
|
|
||||||
# Combine most recent and filtered historical
|
# Combine most recent and filtered historical
|
||||||
Enum.filter([most_recent_data | historical_data], & &1)
|
Enum.filter([most_recent_data | historical_data], & &1)
|
||||||
|
|
@ -628,4 +625,10 @@ defmodule AprsmeWeb.MapLive.DataBuilder do
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -197,12 +197,7 @@ defmodule AprsmeWeb.MapLive.HistoricalLoader do
|
||||||
end
|
end
|
||||||
|
|
||||||
# If tracking a callsign and this is the first batch, also load RF path stations
|
# If tracking a callsign and this is the first batch, also load RF path stations
|
||||||
socket =
|
socket = maybe_load_rf_path_stations(socket, batch_offset, historical_packets)
|
||||||
if socket.assigns.tracked_callsign != "" and batch_offset == 0 do
|
|
||||||
load_rf_path_stations(socket, historical_packets)
|
|
||||||
else
|
|
||||||
socket
|
|
||||||
end
|
|
||||||
|
|
||||||
process_loaded_packets(socket, historical_packets, packet_data_list, batch_offset)
|
process_loaded_packets(socket, historical_packets, packet_data_list, batch_offset)
|
||||||
else
|
else
|
||||||
|
|
@ -424,6 +419,14 @@ defmodule AprsmeWeb.MapLive.HistoricalLoader do
|
||||||
socket
|
socket
|
||||||
end
|
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
|
defp load_rf_path_stations(socket, packets) do
|
||||||
# Extract unique RF path stations from all packets
|
# Extract unique RF path stations from all packets
|
||||||
rf_path_stations =
|
rf_path_stations =
|
||||||
|
|
|
||||||
|
|
@ -109,13 +109,7 @@ defmodule AprsmeWeb.MapLive.PacketProcessor do
|
||||||
marker_data = PacketUtils.build_packet_data(packet, true, get_locale(socket))
|
marker_data = PacketUtils.build_packet_data(packet, true, get_locale(socket))
|
||||||
|
|
||||||
if marker_data do
|
if marker_data do
|
||||||
# Only show new packet popup if no station popup is currently open
|
send_marker_with_popup_check(socket, marker_data)
|
||||||
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
|
|
||||||
else
|
else
|
||||||
socket
|
socket
|
||||||
end
|
end
|
||||||
|
|
@ -167,4 +161,13 @@ defmodule AprsmeWeb.MapLive.PacketProcessor do
|
||||||
# This function should be moved to DisplayManager module
|
# This function should be moved to DisplayManager module
|
||||||
socket
|
socket
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue