kopia lustrzana
https://github.com/quitesimpleorg/hs9001.git
synced 2024-06-10 11:11:16 +02:00
Albert S
3a6a1b2aa9
Remove hack that only starts searching when two chars have been entered Improve performance by adding LIMIT clause instead.
70 wiersze
1.4 KiB
Go
70 wiersze
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"database/sql"
|
|
"io"
|
|
"log"
|
|
"strings"
|
|
)
|
|
|
|
type history struct {
|
|
conn *sql.DB
|
|
}
|
|
|
|
func (h *history) GetHistoryByPrefix(prefix string) (ph []string) {
|
|
opts := searchopts{}
|
|
o := "DESC"
|
|
opts.order = &o
|
|
lim := 100
|
|
opts.limit = &lim
|
|
cmdqry := prefix + "%"
|
|
opts.command = &cmdqry
|
|
results := search(h.conn, opts)
|
|
for e := results.Back(); e != nil; e = e.Prev() {
|
|
entry, ok := e.Value.(*HistoryEntry)
|
|
if !ok {
|
|
log.Panic("Failed to retrieve entries")
|
|
}
|
|
ph = append(ph, entry.cmd)
|
|
}
|
|
return
|
|
}
|
|
func (h *history) GetHistoryByPattern(pattern string) (ph []string, pos []int) {
|
|
opts := searchopts{}
|
|
o := "DESC"
|
|
opts.order = &o
|
|
lim := 100
|
|
opts.limit = &lim
|
|
cmdqry := "%" + pattern + "%"
|
|
opts.command = &cmdqry
|
|
results := search(h.conn, opts)
|
|
for e := results.Back(); e != nil; e = e.Prev() {
|
|
entry, ok := e.Value.(*HistoryEntry)
|
|
if !ok {
|
|
log.Panic("Failed to retrieve entries")
|
|
}
|
|
ph = append(ph, entry.cmd)
|
|
pos = append(pos, strings.Index(strings.ToLower(entry.cmd), strings.ToLower(pattern)))
|
|
}
|
|
return
|
|
}
|
|
|
|
func (h *history) ReadHistory(r io.Reader) (num int, err error) {
|
|
panic("not implemented")
|
|
}
|
|
func (h *history) WriteHistory(w io.Writer) (num int, err error) {
|
|
panic("not implemented")
|
|
}
|
|
func (h *history) AppendHistory(item string) {
|
|
panic("not implemented")
|
|
}
|
|
func (h *history) ClearHistory() {
|
|
panic("not implemented")
|
|
}
|
|
func (h *history) RLock() {
|
|
//noop
|
|
}
|
|
func (h *history) RUnlock() {
|
|
//noop
|
|
}
|