Fix catastrophic targets query and remove emoji from night mode buttons

The seasonal peak subquery used a correlated SELECT inside a GROUP BY,
causing a full nightly_cache scan per object (210-270s for 14k objects).
Replaced with a simple MAX() GROUP BY — now instant.

Also added three indexes on nightly_cache(night_date) that were missing
and causing all dashboard queries to run 2+ second full table scans.

Replaced 🔴 emoji in night mode buttons with CSS circles.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-17 11:02:24 +02:00
parent 4fbc578413
commit a562dae1e3
3 changed files with 31 additions and 12 deletions
+4
View File
@@ -44,6 +44,10 @@ async fn run_migrations(pool: &SqlitePool) -> anyhow::Result<()> {
"ALTER TABLE catalog ADD COLUMN arp_num INTEGER",
"ALTER TABLE catalog ADD COLUMN melotte_num INTEGER",
"ALTER TABLE catalog ADD COLUMN collinder_num INTEGER",
// Performance indexes for nightly_cache date-range queries
"CREATE INDEX IF NOT EXISTS idx_nc_date ON nightly_cache(night_date)",
"CREATE INDEX IF NOT EXISTS idx_nc_date_alt ON nightly_cache(night_date, max_alt_deg)",
"CREATE INDEX IF NOT EXISTS idx_nc_catalog_date ON nightly_cache(catalog_id, night_date)",
];
for sql in migrations {
match sqlx::query(sql).execute(pool).await {