aprs.me/priv/repo/migrations/20250802143345_add_upper_sender_index.exs
Graham McIntire 1e7817646b
perf: Implement performance optimizations without caching
- Optimized list concatenation in PacketConsumer from O(n) to O(1) by prepending events
- Refactored coordinate rounding to avoid recreating anonymous functions on each call
- Added database indexes for case-insensitive searches on upper(sender) and upper(base_callsign)
- Implemented RegexCache to avoid recompiling regex patterns for wildcard device matching
- Added compound index on upper(sender) with received_at for efficient sorted queries

These changes improve performance in hot paths:
- Packet batching is now more efficient with better list operations
- Coordinate processing avoids function allocation overhead
- Database queries using UPPER() now use functional indexes
- Device wildcard matching no longer recompiles regex on every lookup

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-02 09:36:50 -05:00

31 lines
1,014 B
Elixir

defmodule Aprsme.Repo.Migrations.AddUpperSenderIndex do
use Ecto.Migration
@disable_ddl_transaction true
@disable_migration_lock true
def up do
# Create functional index for case-insensitive sender searches
execute """
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_packets_upper_sender
ON packets (upper(sender))
"""
# Also add index for base_callsign which is frequently searched
execute """
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_packets_upper_base_callsign
ON packets (upper(base_callsign))
"""
# Add compound index for sender with received_at for efficient sorting
execute """
CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_packets_upper_sender_received_at
ON packets (upper(sender), received_at DESC)
"""
end
def down do
execute "DROP INDEX IF EXISTS idx_packets_upper_sender"
execute "DROP INDEX IF EXISTS idx_packets_upper_base_callsign"
execute "DROP INDEX IF EXISTS idx_packets_upper_sender_received_at"
end
end