From 3abc135b9c75eadf57cdd13c6d4d19e0e4673a21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Pr=C3=A9?= Date: Tue, 2 Jun 2026 09:40:45 +0200 Subject: [PATCH 1/2] fix: index http_transactions.container_name to speed up pending page The pending page's container filter runs SELECT DISTINCT container_name across pending_requests, request_logs, and http_transactions. The first two are indexed; http_transactions was not, forcing a full scan of a BLOB-heavy table (~170k rows, the bulk of a 20 GB database). On a DB this size, GET /pending took ~10s. Adding the index drops it to sub-second (measured 11.8s -> 0.74s cold, 0.016s warm). Co-Authored-By: Claude Opus 4.8 (1M context) --- internal/greyproxy/migrations.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/internal/greyproxy/migrations.go b/internal/greyproxy/migrations.go index 9452f65..3aefd5b 100644 --- a/internal/greyproxy/migrations.go +++ b/internal/greyproxy/migrations.go @@ -239,6 +239,12 @@ var migrations = []string{ // returned by the middleware in its hello response. NULL for middlewares // that did not declare a name; the UI falls back to middleware_url. `ALTER TABLE middleware_events ADD COLUMN middleware_name TEXT;`, + + // Migration 15: Index http_transactions.container_name to speed up the + // container filter on the pending page. Without it, the DISTINCT + // container_name lookup full-scans http_transactions (BLOB-heavy), which + // made GET /pending take ~30s on large databases. + `CREATE INDEX IF NOT EXISTS idx_http_transactions_container ON http_transactions(container_name);`, } func runMigrations(db *sql.DB) error { From 73fddc8ddad3e395409a2be858a4cfb8f516c6b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Pr=C3=A9?= Date: Tue, 2 Jun 2026 15:22:50 +0200 Subject: [PATCH 2/2] test: update migration count to 15 after adding container index The new idx_http_transactions_container migration brings the total to 15, but TestMigrations still asserted 14. Update the expected count. Co-Authored-By: Claude Opus 4.8 (1M context) --- internal/greyproxy/crud_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/greyproxy/crud_test.go b/internal/greyproxy/crud_test.go index 5831048..219d3f5 100644 --- a/internal/greyproxy/crud_test.go +++ b/internal/greyproxy/crud_test.go @@ -649,8 +649,8 @@ func TestMigrations(t *testing.T) { // Verify migration versions were recorded var count int _ = db.ReadDB().QueryRow("SELECT COUNT(*) FROM schema_migrations").Scan(&count) - if count != 14 { - t.Errorf("expected 14 migration versions, got %d", count) + if count != 15 { + t.Errorf("expected 15 migration versions, got %d", count) } }