From dc65fffd7b7203257887b52b41d282b7032d561d Mon Sep 17 00:00:00 2001 From: David Dworken Date: Sat, 18 Feb 2023 22:26:18 -0800 Subject: [PATCH] Add an index on end_time to ensure that initial queries are fast to fix #68 --- client/data/data.go | 2 +- client/hctx/hctx.go | 1 + client/lib/tui.go | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/client/data/data.go b/client/data/data.go index b4da535..4406b4d 100644 --- a/client/data/data.go +++ b/client/data/data.go @@ -37,7 +37,7 @@ type HistoryEntry struct { HomeDirectory string `json:"home_directory" gorm:"uniqueIndex:compositeindex"` ExitCode int `json:"exit_code" gorm:"uniqueIndex:compositeindex"` StartTime time.Time `json:"start_time" gorm:"uniqueIndex:compositeindex"` - EndTime time.Time `json:"end_time" gorm:"uniqueIndex:compositeindex"` + EndTime time.Time `json:"end_time" gorm:"uniqueIndex:compositeindex,index:end_time_index"` DeviceId string `json:"device_id" gorm:"uniqueIndex:compositeindex"` CustomColumns CustomColumns `json:"custom_columns"` } diff --git a/client/hctx/hctx.go b/client/hctx/hctx.go index dc82e29..0c6998a 100644 --- a/client/hctx/hctx.go +++ b/client/hctx/hctx.go @@ -102,6 +102,7 @@ func OpenLocalSqliteDb() (*gorm.DB, error) { } db.AutoMigrate(&data.HistoryEntry{}) db.Exec("PRAGMA journal_mode = WAL") + db.Exec("CREATE INDEX IF NOT EXISTS end_time_index ON history_entries(end_time)") return db, nil } diff --git a/client/lib/tui.go b/client/lib/tui.go index 5040da2..250ee17 100644 --- a/client/lib/tui.go +++ b/client/lib/tui.go @@ -11,12 +11,12 @@ import ( "github.com/charmbracelet/bubbles/key" "github.com/charmbracelet/bubbles/spinner" - "github.com/ddworken/hishtory/client/table" "github.com/charmbracelet/bubbles/textinput" tea "github.com/charmbracelet/bubbletea" "github.com/charmbracelet/lipgloss" "github.com/ddworken/hishtory/client/data" "github.com/ddworken/hishtory/client/hctx" + "github.com/ddworken/hishtory/client/table" "github.com/ddworken/hishtory/shared" "github.com/muesli/termenv" "golang.org/x/term"