Add an index on end_time to ensure that initial queries are fast to fix #68

This commit is contained in:
David Dworken 2023-02-18 22:26:18 -08:00
parent c31a75e768
commit dc65fffd7b
No known key found for this signature in database
3 changed files with 3 additions and 2 deletions

View File

@ -37,7 +37,7 @@ type HistoryEntry struct {
HomeDirectory string `json:"home_directory" gorm:"uniqueIndex:compositeindex"` HomeDirectory string `json:"home_directory" gorm:"uniqueIndex:compositeindex"`
ExitCode int `json:"exit_code" gorm:"uniqueIndex:compositeindex"` ExitCode int `json:"exit_code" gorm:"uniqueIndex:compositeindex"`
StartTime time.Time `json:"start_time" 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"` DeviceId string `json:"device_id" gorm:"uniqueIndex:compositeindex"`
CustomColumns CustomColumns `json:"custom_columns"` CustomColumns CustomColumns `json:"custom_columns"`
} }

View File

@ -102,6 +102,7 @@ func OpenLocalSqliteDb() (*gorm.DB, error) {
} }
db.AutoMigrate(&data.HistoryEntry{}) db.AutoMigrate(&data.HistoryEntry{})
db.Exec("PRAGMA journal_mode = WAL") db.Exec("PRAGMA journal_mode = WAL")
db.Exec("CREATE INDEX IF NOT EXISTS end_time_index ON history_entries(end_time)")
return db, nil return db, nil
} }

View File

@ -11,12 +11,12 @@ import (
"github.com/charmbracelet/bubbles/key" "github.com/charmbracelet/bubbles/key"
"github.com/charmbracelet/bubbles/spinner" "github.com/charmbracelet/bubbles/spinner"
"github.com/ddworken/hishtory/client/table"
"github.com/charmbracelet/bubbles/textinput" "github.com/charmbracelet/bubbles/textinput"
tea "github.com/charmbracelet/bubbletea" tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/lipgloss" "github.com/charmbracelet/lipgloss"
"github.com/ddworken/hishtory/client/data" "github.com/ddworken/hishtory/client/data"
"github.com/ddworken/hishtory/client/hctx" "github.com/ddworken/hishtory/client/hctx"
"github.com/ddworken/hishtory/client/table"
"github.com/ddworken/hishtory/shared" "github.com/ddworken/hishtory/shared"
"github.com/muesli/termenv" "github.com/muesli/termenv"
"golang.org/x/term" "golang.org/x/term"