Fix duplicate indexes and missing socket assigns

- Remove duplicate received_at indexes (packets_received_at_asc_idx and packets_recent_hour_idx)
  that were consuming 423 MB, keeping only packets_received_at_idx
- Fix KeyError by initializing missing :all_packets and :visible_packets in socket assigns
- All tests now pass successfully

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Graham McIntire 2025-07-15 11:01:27 -05:00
parent c431a45b0b
commit e97d1d6e33
No known key found for this signature in database
2 changed files with 25 additions and 0 deletions

View file

@ -153,6 +153,8 @@ defmodule AprsmeWeb.MapLive.Index do
defp assign_defaults(socket, one_hour_ago) do
assign(socket,
packets: [],
all_packets: %{},
visible_packets: %{},
page_title: "APRS Map",
packet_state: PacketManager.init_packet_state(),
station_popup_open: false,

View file

@ -0,0 +1,23 @@
defmodule Aprsme.Repo.Migrations.RemoveDuplicateReceivedAtIndexes do
use Ecto.Migration
def up do
# Remove duplicate indexes on received_at column
# Keep only packets_received_at_idx which is the most general purpose
drop_if_exists index(:packets, [:received_at], name: :packets_received_at_asc_idx)
drop_if_exists index(:packets, [:received_at], name: :packets_recent_hour_idx)
end
def down do
# Recreate the removed indexes
create_if_not_exists index(:packets, [:received_at],
name: :packets_received_at_asc_idx,
comment: "Index for cleanup worker queries (ascending for old packets)"
)
create_if_not_exists index(:packets, [:received_at],
name: :packets_recent_hour_idx,
comment: "Index for recent packet queries"
)
end
end