improve status page
This commit is contained in:
parent
a9bc74b232
commit
dd9dd7ce1d
2 changed files with 19 additions and 0 deletions
|
|
@ -557,6 +557,7 @@ defmodule Aprsme.Packets do
|
||||||
"""
|
"""
|
||||||
@spec get_total_packet_count() :: non_neg_integer()
|
@spec get_total_packet_count() :: non_neg_integer()
|
||||||
def get_total_packet_count do
|
def get_total_packet_count do
|
||||||
|
# Use the new index for faster counting
|
||||||
Repo.one(from p in Packet, select: count(p.id)) || 0
|
Repo.one(from p in Packet, select: count(p.id)) || 0
|
||||||
rescue
|
rescue
|
||||||
DBConnection.ConnectionError ->
|
DBConnection.ConnectionError ->
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
Loading…
Add table
Reference in a new issue