mirror da
https://github.com/quitesimpleorg/hs9001.git
synced 2024-11-25 01:12:36 +01:00
bash-ctrlr: Improve reverse bash search performance
Remove hack that only starts searching when two chars have been entered Improve performance by adding LIMIT clause instead.
This commit is contained in:
parent
1a6c75cea9
commit
3a6a1b2aa9
22
history.go
22
history.go
@ -12,16 +12,15 @@ type history struct {
|
||||
}
|
||||
|
||||
func (h *history) GetHistoryByPrefix(prefix string) (ph []string) {
|
||||
/* Hack for performance reasons */
|
||||
if len(prefix) < 2 {
|
||||
return
|
||||
}
|
||||
opts := searchopts{}
|
||||
opts.order = "DESC"
|
||||
o := "DESC"
|
||||
opts.order = &o
|
||||
lim := 100
|
||||
opts.limit = &lim
|
||||
cmdqry := prefix + "%"
|
||||
opts.command = &cmdqry
|
||||
results := search(h.conn, opts)
|
||||
for e := results.Front(); e != nil; e = e.Next() {
|
||||
for e := results.Back(); e != nil; e = e.Prev() {
|
||||
entry, ok := e.Value.(*HistoryEntry)
|
||||
if !ok {
|
||||
log.Panic("Failed to retrieve entries")
|
||||
@ -31,16 +30,15 @@ func (h *history) GetHistoryByPrefix(prefix string) (ph []string) {
|
||||
return
|
||||
}
|
||||
func (h *history) GetHistoryByPattern(pattern string) (ph []string, pos []int) {
|
||||
/* Hack for performance reasons */
|
||||
if len(pattern) < 2 {
|
||||
return
|
||||
}
|
||||
opts := searchopts{}
|
||||
opts.order = "DESC"
|
||||
o := "DESC"
|
||||
opts.order = &o
|
||||
lim := 100
|
||||
opts.limit = &lim
|
||||
cmdqry := "%" + pattern + "%"
|
||||
opts.command = &cmdqry
|
||||
results := search(h.conn, opts)
|
||||
for e := results.Front(); e != nil; e = e.Next() {
|
||||
for e := results.Back(); e != nil; e = e.Prev() {
|
||||
entry, ok := e.Value.(*HistoryEntry)
|
||||
if !ok {
|
||||
log.Panic("Failed to retrieve entries")
|
||||
|
19
main.go
19
main.go
@ -157,7 +157,8 @@ type searchopts struct {
|
||||
after *time.Time
|
||||
before *time.Time
|
||||
retval *int
|
||||
order string
|
||||
order *string
|
||||
limit *int
|
||||
}
|
||||
|
||||
func search(conn *sql.DB, opts searchopts) list.List {
|
||||
@ -188,7 +189,18 @@ func search(conn *sql.DB, opts searchopts) list.List {
|
||||
args = append(args, opts.retval)
|
||||
}
|
||||
sb.WriteString("ORDER BY timestamp ")
|
||||
sb.WriteString("ASC ")
|
||||
if opts.order != nil {
|
||||
sb.WriteString(*opts.order)
|
||||
sb.WriteRune(' ')
|
||||
} else {
|
||||
sb.WriteString("ASC ")
|
||||
}
|
||||
|
||||
if opts.limit != nil {
|
||||
sb.WriteString("LIMIT ")
|
||||
sb.WriteString(strconv.Itoa(*opts.limit))
|
||||
sb.WriteRune(' ')
|
||||
}
|
||||
|
||||
queryStmt := sb.String()
|
||||
|
||||
@ -353,7 +365,8 @@ func main() {
|
||||
q := strings.Join(args, " ")
|
||||
|
||||
opts := searchopts{}
|
||||
opts.order = "ASC"
|
||||
o := "ASC"
|
||||
opts.order = &o
|
||||
if q != "" {
|
||||
cmd := "%" + q + "%"
|
||||
opts.command = &cmd
|
||||
|
Caricamento…
Fai riferimento in un nuovo problema
Block a user