A modern and elegant dashboard for network traffic visualization and analysis.
perf(db): drop unused traffic-sum expression indexes
luolei97448655f485
diff --git a/apps/collector/src/database/schema.ts b/apps/collector/src/database/schema.tsindex decee54..a10838a 100644--- a/apps/collector/src/database/schema.ts+++ b/apps/collector/src/database/schema.ts@@ -460,15 +460,14 @@ export const INDEXES = [`CREATE INDEX IF NOT EXISTS idx_rule_domain_traffic ON rule_domain_traffic(backend_id, rule);`,`CREATE INDEX IF NOT EXISTS idx_rule_ip_traffic ON rule_ip_traffic(backend_id, rule);`,- // Stats indexes+ // Stats indexes.+ // No expression indexes on (total_download + total_upload): every hot query+ // filters by backend_id first, so SQLite never used them for the ORDER BY —+ // they only added write amplification on the four hottest tables.`CREATE INDEX IF NOT EXISTS idx_domain_stats_backend ON domain_stats(backend_id);`,- `CREATE INDEX IF NOT EXISTS idx_domain_stats_traffic ON domain_stats(total_download + total_upload);`,`CREATE INDEX IF NOT EXISTS idx_ip_stats_backend ON ip_stats(backend_id);`,- `CREATE INDEX IF NOT EXISTS idx_ip_stats_traffic ON ip_stats(total_download + total_upload);`,`CREATE INDEX IF NOT EXISTS idx_proxy_stats_backend ON proxy_stats(backend_id);`,- `CREATE INDEX IF NOT EXISTS idx_proxy_stats_traffic ON proxy_stats(total_download + total_upload);`,`CREATE INDEX IF NOT EXISTS idx_rule_stats_backend ON rule_stats(backend_id);`,- `CREATE INDEX IF NOT EXISTS idx_rule_stats_traffic ON rule_stats(total_download + total_upload);`,`CREATE INDEX IF NOT EXISTS idx_rule_proxy_map ON rule_proxy_map(backend_id, rule, proxy);`,`CREATE INDEX IF NOT EXISTS idx_country_stats_backend ON country_stats(backend_id);`,`CREATE INDEX IF NOT EXISTS idx_hourly_stats_backend ON hourly_stats(backend_id);`,diff --git a/apps/collector/src/modules/db/db.ts b/apps/collector/src/modules/db/db.tsindex 10a470f..097a456 100644--- a/apps/collector/src/modules/db/db.ts+++ b/apps/collector/src/modules/db/db.ts@@ -157,6 +157,13 @@ export class StatsDatabase {this.db.exec(stmt);}+ // Drop legacy (total_download + total_upload) expression indexes: the+ // planner never used them (queries filter by backend_id first) and they+ // amplified every write to the four hottest tables.+ for (const idx of ['idx_domain_stats_traffic', 'idx_ip_stats_traffic', 'idx_proxy_stats_traffic', 'idx_rule_stats_traffic']) {+ this.db.exec(`DROP INDEX IF EXISTS ${idx}`);+ }+// Migration: Add type column if not exists (for older databases)try {this.db.exec(`ALTER TABLE backend_configs ADD COLUMN type TEXT DEFAULT 'clash'`);