refactoring
This commit is contained in:
parent
e7214f5064
commit
3b0c1213f4
3 changed files with 22 additions and 27 deletions
|
|
@ -558,7 +558,7 @@ let MapAPRSMap = {
|
|||
historical: false,
|
||||
is_most_recent_for_callsign: true,
|
||||
callsign_group: data.callsign_group || data.callsign || incomingCallsign,
|
||||
popup: self.buildPopupContent(data),
|
||||
popup: data.popup || self.buildPopupContent(data),
|
||||
openPopup: true,
|
||||
});
|
||||
});
|
||||
|
|
@ -589,7 +589,7 @@ let MapAPRSMap = {
|
|||
self.addMarker({
|
||||
...data,
|
||||
historical: true,
|
||||
popup: self.buildPopupContent(data),
|
||||
popup: data.popup || self.buildPopupContent(data),
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -629,7 +629,7 @@ let MapAPRSMap = {
|
|||
self.addMarker({
|
||||
...packet,
|
||||
historical: true,
|
||||
popup: self.buildPopupContent(packet),
|
||||
popup: packet.popup || self.buildPopupContent(packet),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -1069,12 +1069,6 @@ let MapAPRSMap = {
|
|||
content += `<div class="aprs-comment">${comment}</div>`;
|
||||
}
|
||||
|
||||
if (data.lat && data.lng) {
|
||||
content += `<div class="aprs-coords">
|
||||
${data.lat.toFixed(4)}, ${data.lng.toFixed(4)}
|
||||
</div>`;
|
||||
}
|
||||
|
||||
if (data.timestamp) {
|
||||
let date;
|
||||
if (typeof data.timestamp === "number") {
|
||||
|
|
|
|||
|
|
@ -68,8 +68,7 @@ defmodule AprsWeb.MapLive.CallsignView do
|
|||
# Don't load packets here - wait for map_ready event
|
||||
# socket = load_callsign_packets(socket, normalized_callsign)
|
||||
|
||||
# Schedule regular cleanup of old packets from the map
|
||||
Process.send_after(self(), :cleanup_old_packets, 60_000)
|
||||
# No longer need scheduled cleanup - packets are cleaned up automatically when new ones arrive
|
||||
# Auto-start replay after a short delay
|
||||
Process.send_after(self(), :auto_start_replay, 2000)
|
||||
|
||||
|
|
@ -192,6 +191,9 @@ defmodule AprsWeb.MapLive.CallsignView do
|
|||
west: to_float(bounds["west"])
|
||||
}
|
||||
|
||||
# Clean up old packets first
|
||||
socket = cleanup_old_packets(socket)
|
||||
|
||||
# Remove out-of-bounds visible packets
|
||||
new_visible_packets =
|
||||
socket.assigns.visible_packets
|
||||
|
|
@ -264,7 +266,6 @@ defmodule AprsWeb.MapLive.CallsignView do
|
|||
end
|
||||
|
||||
def handle_info(:replay_next_packet, socket), do: handle_replay_next_packet(socket)
|
||||
def handle_info(:cleanup_old_packets, socket), do: handle_cleanup_old_packets(socket)
|
||||
|
||||
def handle_info(%Phoenix.Socket.Broadcast{topic: "aprs_messages", event: "packet", payload: packet}, socket) do
|
||||
# Only process packets for the specific callsign being viewed
|
||||
|
|
@ -280,6 +281,9 @@ defmodule AprsWeb.MapLive.CallsignView do
|
|||
def handle_info(_msg, socket), do: {:noreply, socket}
|
||||
|
||||
defp handle_info_postgres_packet(packet, socket) do
|
||||
# Clean up old packets before adding the new one
|
||||
socket = cleanup_old_packets(socket)
|
||||
|
||||
key = System.unique_integer([:positive])
|
||||
updated_visible_packets = Map.put(socket.assigns.visible_packets, key, packet)
|
||||
socket = assign(socket, visible_packets: updated_visible_packets)
|
||||
|
|
@ -625,19 +629,16 @@ defmodule AprsWeb.MapLive.CallsignView do
|
|||
"""
|
||||
end
|
||||
|
||||
defp handle_cleanup_old_packets(socket) do
|
||||
# Schedule next cleanup
|
||||
Process.send_after(self(), :cleanup_old_packets, 60_000)
|
||||
|
||||
defp cleanup_old_packets(socket, age_threshold_seconds \\ 3600) do
|
||||
# Update packet age threshold
|
||||
one_hour_ago = DateTime.add(DateTime.utc_now(), -3600, :second)
|
||||
socket = assign(socket, packet_age_threshold: one_hour_ago)
|
||||
threshold_time = DateTime.add(DateTime.utc_now(), -age_threshold_seconds, :second)
|
||||
socket = assign(socket, packet_age_threshold: threshold_time)
|
||||
|
||||
# Remove expired packets from visible_packets
|
||||
expired_keys =
|
||||
socket.assigns.visible_packets
|
||||
|> Enum.filter(fn {_key, packet} ->
|
||||
not packet_within_time_threshold?(packet, one_hour_ago)
|
||||
not packet_within_time_threshold?(packet, threshold_time)
|
||||
end)
|
||||
|> Enum.map(fn {key, _} -> key end)
|
||||
|
||||
|
|
@ -653,9 +654,7 @@ defmodule AprsWeb.MapLive.CallsignView do
|
|||
|
||||
# Use Map.drop/2 for better performance
|
||||
updated_visible_packets = Map.drop(socket.assigns.visible_packets, expired_keys)
|
||||
socket = assign(socket, visible_packets: updated_visible_packets)
|
||||
|
||||
{:noreply, socket}
|
||||
assign(socket, visible_packets: updated_visible_packets)
|
||||
end
|
||||
|
||||
defp packet_within_time_threshold?(packet, threshold) do
|
||||
|
|
@ -867,6 +866,9 @@ defmodule AprsWeb.MapLive.CallsignView do
|
|||
visible_packets = build_visible_packets(latest_packet)
|
||||
socket = maybe_push_latest_marker(socket, latest_packet)
|
||||
|
||||
# Clean up old packets before assigning new visible packets
|
||||
socket = cleanup_old_packets(socket)
|
||||
|
||||
assign(socket,
|
||||
last_known_position: last_known_position,
|
||||
visible_packets: visible_packets,
|
||||
|
|
|
|||
|
|
@ -180,7 +180,7 @@ defmodule AprsWeb.MapLive.PacketUtils do
|
|||
end
|
||||
end
|
||||
|
||||
defp build_standard_popup_html(packet_info, lat, lon) do
|
||||
defp build_standard_popup_html(packet_info, _lat, _lon) do
|
||||
comment_html =
|
||||
if packet_info.comment == "",
|
||||
do: "",
|
||||
|
|
@ -204,7 +204,6 @@ defmodule AprsWeb.MapLive.PacketUtils do
|
|||
<div class="aprs-popup">
|
||||
<div class="aprs-callsign"><strong><a href="/#{packet_info.callsign}">#{packet_info.callsign}</a></strong></div>
|
||||
#{comment_html}
|
||||
<div class="aprs-coords">#{Float.round(to_float(lat), 4)}, #{Float.round(to_float(lon), 4)}</div>
|
||||
#{timestamp_html}
|
||||
</div>
|
||||
"""
|
||||
|
|
@ -217,9 +216,9 @@ defmodule AprsWeb.MapLive.PacketUtils do
|
|||
timestamp_html =
|
||||
if timestamp_dt do
|
||||
"""
|
||||
<div class="aprs-timestamp" style="font-size: 11px; color: #6b7280; padding-top: 0; padding-bottom: 4px;">
|
||||
<div style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; font-size: 12px; line-height: 1.4;">#{TimeHelpers.time_ago_in_words(timestamp_dt)}</div>
|
||||
<div style="font-family: monospace;">#{Calendar.strftime(timestamp_dt, "%Y-%m-%d %H:%M:%S UTC")}</div>
|
||||
<div class="aprs-timestamp">
|
||||
<div>#{TimeHelpers.time_ago_in_words(timestamp_dt)}</div>
|
||||
<div class="text-slate-400">#{Calendar.strftime(timestamp_dt, "%Y-%m-%d %H:%M:%S UTC")}</div>
|
||||
</div>
|
||||
"""
|
||||
else
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue