Drop the pre-insert aprs_messages broadcast in Is.dispatch (subscribers already get a richer payload via postgres:aprsme_packets after insert). Switch PacketsLive.CallsignView to the per-callsign packets:<CS> topic so it only receives relevant packets instead of filtering every one. In PacketConsumer: reuse the received_at stamped in Is.dispatch instead of calling DateTime.utc_now/0 per packet; drop the duplicate struct_to_map pass (Is.dispatch already handled it); fold coordinate validation and Geo.Point construction into set_lat_lon + create_location_geometry so coords are normalized once; extract device_identifier from the already- normalized attrs; pre-build the broadcast payload once (identifier pick, lat/lon aliases, routing callsign) so the async broadcast task no longer does Map.drop/Map.merge per packet. Rewrite PacketSanitizer.sanitize_packet / sanitize_data_map with Map.new/2 instead of Enum.reduce + Map.put — one allocation per packet instead of N. Also compute has_weather in Packet.changeset/2 so direct-changeset inserts (tests, backfills) populate it the same way the GenStage pipeline does.
44 lines
1.4 KiB
Elixir
44 lines
1.4 KiB
Elixir
defmodule AprsmeWeb.PacketsLive.CallsignViewTest do
|
|
use AprsmeWeb.ConnCase
|
|
|
|
import Phoenix.LiveViewTest
|
|
|
|
describe "live packet broadcast" do
|
|
test "handles raw broadcast packet without :data key", %{conn: conn} do
|
|
{:ok, view, _html} = live(conn, "/packets/DB0WUN-13")
|
|
|
|
# Simulate a raw broadcast payload (as it arrives from the APRS pipeline)
|
|
# This map does NOT have a :data key — only %Packet{} structs do
|
|
raw_payload = %{
|
|
sender: "DB0WUN-13",
|
|
data_type: :weather,
|
|
destination: "APN000",
|
|
path: "TCPIP*,qAC,T2EISBERG",
|
|
base_callsign: "DB0WUN",
|
|
ssid: "13",
|
|
received_at: DateTime.utc_now(),
|
|
latitude: Decimal.new("50.0001"),
|
|
longitude: Decimal.new("12.1393"),
|
|
temperature: 31,
|
|
humidity: 89,
|
|
wind_speed: 3,
|
|
comment: "232/003g009t031r000p000P000b10215h89L000eMB63",
|
|
device_identifier: "APN000",
|
|
data_extended: %{
|
|
data_type: :weather,
|
|
comment: "232/003g009t031r000p000P000b10215h89L000eMB63",
|
|
latitude: Decimal.new("50.0001"),
|
|
longitude: Decimal.new("12.1393"),
|
|
symbol_code: "_",
|
|
symbol_table_id: "/"
|
|
}
|
|
}
|
|
|
|
Phoenix.PubSub.broadcast(Aprsme.PubSub, "packets:DB0WUN-13", {:postgres_packet, raw_payload})
|
|
|
|
# Should render without crashing
|
|
html = render(view)
|
|
assert html =~ "DB0WUN-13"
|
|
end
|
|
end
|
|
end
|