Fix live updates for /info/:call page by sending all packet fields
Update the PostgreSQL notify_packets_insert trigger to send all necessary fields when broadcasting new packets. Previously only minimal fields were sent (id, sender, lat, lon, inserted_at), which prevented the info page from displaying complete packet information during live updates. The trigger now includes: - Position data (lat, lon, altitude, course, speed) - Symbol data (symbol_table_id, symbol_code) - Device data (device_identifier, path) - Metadata (received_at, comment, raw_packet) - PHG data (phg_power, phg_height, phg_gain, phg_directivity) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
521aeea3c5
commit
8c84706c6b
3 changed files with 94 additions and 0 deletions
|
|
@ -22,6 +22,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- Weather queries now use indexed `has_weather` column
|
- Weather queries now use indexed `has_weather` column
|
||||||
- Spatial queries optimized with geography cast index
|
- Spatial queries optimized with geography cast index
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
- PostgreSQL notify trigger now sends all required fields for info page updates
|
||||||
|
- Info page real-time updates now display all packet details correctly
|
||||||
|
|
||||||
## [0.2.0] - 2025-07-26
|
## [0.2.0] - 2025-07-26
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,16 @@ This document tracks potential improvements identified during the multi-replica
|
||||||
- Weather queries: ~2-3ms
|
- Weather queries: ~2-3ms
|
||||||
- Distinct callsign queries: ~4ms
|
- Distinct callsign queries: ~4ms
|
||||||
|
|
||||||
|
### ✅ Fix PostgreSQL Notification Trigger for Info Page Updates (2025-07-28)
|
||||||
|
- **Status**: Completed
|
||||||
|
- **Impact**: High - Fix real-time updates on info pages
|
||||||
|
- **Implementation**:
|
||||||
|
- Updated `notify_packets_insert` trigger to send all required fields
|
||||||
|
- Previously only sent: id, sender, lat, lon, inserted_at
|
||||||
|
- Now includes: altitude, course, speed, symbol data, device info, PHG data, etc.
|
||||||
|
- Info page (/info/:callsign) now updates in real-time with complete packet data
|
||||||
|
- Ensures all UI elements refresh properly when new packets arrive
|
||||||
|
|
||||||
### 3. Add Metrics and Monitoring with Prometheus
|
### 3. Add Metrics and Monitoring with Prometheus
|
||||||
- **Status**: Pending
|
- **Status**: Pending
|
||||||
- **Impact**: High - Production visibility
|
- **Impact**: High - Production visibility
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,80 @@
|
||||||
|
defmodule Aprsme.Repo.Migrations.UpdateNotifyPacketsInsertWithAllFields do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def up do
|
||||||
|
# Drop existing trigger and function
|
||||||
|
execute "DROP TRIGGER IF EXISTS packets_notify_insert ON packets;"
|
||||||
|
execute "DROP FUNCTION IF EXISTS notify_packets_insert();"
|
||||||
|
|
||||||
|
# Create updated function that includes all fields needed by the info page
|
||||||
|
execute """
|
||||||
|
CREATE OR REPLACE FUNCTION notify_packets_insert() RETURNS trigger AS $$
|
||||||
|
DECLARE
|
||||||
|
payload TEXT;
|
||||||
|
BEGIN
|
||||||
|
payload := json_build_object(
|
||||||
|
'id', NEW.id,
|
||||||
|
'sender', NEW.sender,
|
||||||
|
'lat', NEW.lat,
|
||||||
|
'lon', NEW.lon,
|
||||||
|
'altitude', NEW.altitude,
|
||||||
|
'course', NEW.course,
|
||||||
|
'speed', NEW.speed,
|
||||||
|
'symbol_table_id', NEW.symbol_table_id,
|
||||||
|
'symbol_code', NEW.symbol_code,
|
||||||
|
'device_identifier', NEW.device_identifier,
|
||||||
|
'path', NEW.path,
|
||||||
|
'received_at', NEW.received_at,
|
||||||
|
'comment', NEW.comment,
|
||||||
|
'raw_packet', NEW.raw_packet,
|
||||||
|
'phg_power', NEW.phg_power,
|
||||||
|
'phg_height', NEW.phg_height,
|
||||||
|
'phg_gain', NEW.phg_gain,
|
||||||
|
'phg_directivity', NEW.phg_directivity,
|
||||||
|
'inserted_at', NEW.inserted_at
|
||||||
|
)::text;
|
||||||
|
PERFORM pg_notify('aprs_packets', payload);
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql;
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Recreate trigger
|
||||||
|
execute """
|
||||||
|
CREATE TRIGGER packets_notify_insert
|
||||||
|
AFTER INSERT ON packets
|
||||||
|
FOR EACH ROW EXECUTE FUNCTION notify_packets_insert();
|
||||||
|
"""
|
||||||
|
end
|
||||||
|
|
||||||
|
def down do
|
||||||
|
# Drop updated trigger and function
|
||||||
|
execute "DROP TRIGGER IF EXISTS packets_notify_insert ON packets;"
|
||||||
|
execute "DROP FUNCTION IF EXISTS notify_packets_insert();"
|
||||||
|
|
||||||
|
# Restore previous version with minimal fields
|
||||||
|
execute """
|
||||||
|
CREATE OR REPLACE FUNCTION notify_packets_insert() RETURNS trigger AS $$
|
||||||
|
DECLARE
|
||||||
|
payload TEXT;
|
||||||
|
BEGIN
|
||||||
|
payload := json_build_object(
|
||||||
|
'id', NEW.id,
|
||||||
|
'sender', NEW.sender,
|
||||||
|
'lat', NEW.lat,
|
||||||
|
'lon', NEW.lon,
|
||||||
|
'inserted_at', NEW.inserted_at
|
||||||
|
)::text;
|
||||||
|
PERFORM pg_notify('aprs_packets', payload);
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$$ LANGUAGE plpgsql;
|
||||||
|
"""
|
||||||
|
|
||||||
|
execute """
|
||||||
|
CREATE TRIGGER packets_notify_insert
|
||||||
|
AFTER INSERT ON packets
|
||||||
|
FOR EACH ROW EXECUTE FUNCTION notify_packets_insert();
|
||||||
|
"""
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Add table
Reference in a new issue