improve status page

This commit is contained in:
Graham McIntire 2025-07-07 12:20:03 -05:00
parent a9bc74b232
commit dd9dd7ce1d
No known key found for this signature in database
2 changed files with 19 additions and 0 deletions

View file

@ -557,6 +557,7 @@ defmodule Aprsme.Packets do
"""
@spec get_total_packet_count() :: non_neg_integer()
def get_total_packet_count do
# Use the new index for faster counting
Repo.one(from p in Packet, select: count(p.id)) || 0
rescue
DBConnection.ConnectionError ->

View file

@ -0,0 +1,18 @@
defmodule Aprsme.Repo.Migrations.AddCountOptimizationIndex do
use Ecto.Migration
@disable_ddl_transaction true
def up do
# Add a partial index on id that will be used for COUNT(*) queries
# This creates a small, fast index that PostgreSQL can use for counting
execute """
CREATE INDEX CONCURRENTLY IF NOT EXISTS packets_count_idx
ON packets (id)
WHERE id IS NOT NULL
"""
end
def down do
execute "DROP INDEX IF EXISTS packets_count_idx"
end
end