mirror of
https://github.com/ddworken/hishtory.git
synced 2025-02-28 16:31:42 +01:00
Add index of start time so that queries with a LIMIT clause can avoid a full table scan (for #202)
This commit is contained in:
parent
5290f6dfb8
commit
ca90ab65c9
@ -2996,7 +2996,7 @@ func BenchmarkQuery(b *testing.B) {
|
|||||||
// Benchmarked code:
|
// Benchmarked code:
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
ctx := hctx.MakeContext()
|
ctx := hctx.MakeContext()
|
||||||
_, err := lib.Search(ctx, hctx.GetDb(ctx), "echo", 0)
|
_, err := lib.Search(ctx, hctx.GetDb(ctx), "echo", 100)
|
||||||
require.NoError(b, err)
|
require.NoError(b, err)
|
||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ type HistoryEntry struct {
|
|||||||
CurrentWorkingDirectory string `json:"current_working_directory" gorm:"uniqueIndex:compositeindex"`
|
CurrentWorkingDirectory string `json:"current_working_directory" gorm:"uniqueIndex:compositeindex"`
|
||||||
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,index:start_time_index"`
|
||||||
EndTime time.Time `json:"end_time" gorm:"uniqueIndex:compositeindex,index:end_time_index"`
|
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"`
|
||||||
EntryId string `json:"entry_id" gorm:"uniqueIndex:compositeindex,uniqueIndex:entry_id_index"`
|
EntryId string `json:"entry_id" gorm:"uniqueIndex:compositeindex,uniqueIndex:entry_id_index"`
|
||||||
|
@ -103,6 +103,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 start_time_index ON history_entries(start_time)")
|
||||||
db.Exec("CREATE INDEX IF NOT EXISTS end_time_index ON history_entries(end_time)")
|
db.Exec("CREATE INDEX IF NOT EXISTS end_time_index ON history_entries(end_time)")
|
||||||
db.Exec("CREATE INDEX IF NOT EXISTS entry_id_index ON history_entries(entry_id)")
|
db.Exec("CREATE INDEX IF NOT EXISTS entry_id_index ON history_entries(entry_id)")
|
||||||
return db, nil
|
return db, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user