modestly better search, with parameters
This commit is contained in:
parent
d405d02e6f
commit
fcd4170bb2
35
database.go
35
database.go
|
@ -52,6 +52,8 @@ func butwhatabout(name string) (*WhatAbout, error) {
|
|||
return user, nil
|
||||
}
|
||||
|
||||
var honkerinvalidator cache.Invalidator
|
||||
|
||||
func gethonkers(userid int64) []*Honker {
|
||||
rows, err := stmtHonkers.Query(userid)
|
||||
if err != nil {
|
||||
|
@ -195,8 +197,35 @@ func gethonksbyconvoy(userid int64, convoy string) []*Honk {
|
|||
return honks
|
||||
}
|
||||
func gethonksbysearch(userid int64, q string) []*Honk {
|
||||
q = "%" + q + "%"
|
||||
rows, err := stmtHonksBySearch.Query(userid, q, userid)
|
||||
honker := ""
|
||||
withhonker := 0
|
||||
site := ""
|
||||
withsite := 0
|
||||
terms := strings.Split(q, " ")
|
||||
q = "%"
|
||||
for _, t := range terms {
|
||||
if strings.HasPrefix(t, "site:") {
|
||||
site = t[5:]
|
||||
site = "%" + site + "%"
|
||||
withsite = 1
|
||||
continue
|
||||
}
|
||||
if strings.HasPrefix(t, "honker:") {
|
||||
honker = t[7:]
|
||||
xid := fullname(honker, userid)
|
||||
if xid != "" {
|
||||
honker = xid
|
||||
}
|
||||
withhonker = 1
|
||||
continue
|
||||
}
|
||||
if q[0] != '%' {
|
||||
q += " "
|
||||
}
|
||||
q += t
|
||||
}
|
||||
q += "%"
|
||||
rows, err := stmtHonksBySearch.Query(userid, withsite, site, withhonker, honker, honker, q, userid)
|
||||
honks := getsomehonks(rows, err)
|
||||
return honks
|
||||
}
|
||||
|
@ -647,7 +676,7 @@ func prepareStatements(db *sql.DB) {
|
|||
stmtHonksByHonker = preparetodie(db, selecthonks+"join honkers on (honkers.xid = honks.honker or honkers.xid = honks.oonker) where honks.userid = ? and honkers.name = ?"+butnotthose+limit)
|
||||
stmtHonksByXonker = preparetodie(db, selecthonks+" where honks.userid = ? and (honker = ? or oonker = ?)"+butnotthose+limit)
|
||||
stmtHonksByCombo = preparetodie(db, selecthonks+"join honkers on honkers.xid = honks.honker where honks.userid = ? and honkers.combos like ?"+butnotthose+limit)
|
||||
stmtHonksBySearch = preparetodie(db, selecthonks+"where honks.userid = ? and noise like ?"+butnotthose+limit)
|
||||
stmtHonksBySearch = preparetodie(db, selecthonks+"where honks.userid = ? and (? = 0 or xid like ?) and (? = 0 or honks.honker = ? or honks.oonker = ?) and noise like ?"+butnotthose+limit)
|
||||
stmtHonksByConvoy = preparetodie(db, selecthonks+"where (honks.userid = ? or (? = -1 and whofore = 2)) and convoy = ?"+limit)
|
||||
stmtHonksByOntology = preparetodie(db, selecthonks+"join onts on honks.honkid = onts.honkid where onts.ontology = ? and (honks.userid = ? or (? = -1 and honks.whofore = 2))"+limit)
|
||||
|
||||
|
|
27
fun.go
27
fun.go
|
@ -350,10 +350,9 @@ func quickrename(s string, userid int64) string {
|
|||
m = m[:len(m)-1]
|
||||
}
|
||||
|
||||
row := stmtOneHonker.QueryRow(m, userid)
|
||||
var xid string
|
||||
err := row.Scan(&xid)
|
||||
if err == nil {
|
||||
xid := fullname(m, userid)
|
||||
|
||||
if xid != "" {
|
||||
_, name := handles(xid)
|
||||
if name != "" {
|
||||
nonstop = true
|
||||
|
@ -373,7 +372,7 @@ var shortnames = cache.New(cache.Options{Filler: func(userid int64) (map[string]
|
|||
m[h.XID] = h.Name
|
||||
}
|
||||
return m, true
|
||||
}})
|
||||
}, Invalidator: &honkerinvalidator})
|
||||
|
||||
func shortname(userid int64, xid string) string {
|
||||
var m map[string]string
|
||||
|
@ -384,6 +383,24 @@ func shortname(userid int64, xid string) string {
|
|||
return ""
|
||||
}
|
||||
|
||||
var fullnames = cache.New(cache.Options{Filler: func(userid int64) (map[string]string, bool) {
|
||||
honkers := gethonkers(userid)
|
||||
m := make(map[string]string)
|
||||
for _, h := range honkers {
|
||||
m[h.Name] = h.XID
|
||||
}
|
||||
return m, true
|
||||
}, Invalidator: &honkerinvalidator})
|
||||
|
||||
func fullname(name string, userid int64) string {
|
||||
var m map[string]string
|
||||
ok := fullnames.Get(userid, &m)
|
||||
if ok {
|
||||
return m[name]
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func mentionize(s string) string {
|
||||
s = re_mentions.ReplaceAllStringFunc(s, func(m string) string {
|
||||
where := gofish(m)
|
||||
|
|
2
go.mod
2
go.mod
|
@ -7,7 +7,7 @@ require (
|
|||
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859
|
||||
humungus.tedunangst.com/r/go-sqlite3 v1.1.3
|
||||
humungus.tedunangst.com/r/webs v0.6.10
|
||||
humungus.tedunangst.com/r/webs v0.6.11
|
||||
)
|
||||
|
||||
go 1.11
|
||||
|
|
4
go.sum
4
go.sum
|
@ -21,5 +21,5 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
humungus.tedunangst.com/r/go-sqlite3 v1.1.3 h1:G2N4wzDS0NbuvrZtQJhh4F+3X+s7BF8b9ga8k38geUI=
|
||||
humungus.tedunangst.com/r/go-sqlite3 v1.1.3/go.mod h1:FtEEmQM7U2Ey1TuEEOyY1BmphTZnmiEjPsNLEAkpf/M=
|
||||
humungus.tedunangst.com/r/webs v0.6.10 h1:Qe4QW/7us8szAwL68zoIihfkaqsy/7Ys00bfdSPH5/g=
|
||||
humungus.tedunangst.com/r/webs v0.6.10/go.mod h1:Ho+nmafD/aUWF7LnH+Yl2/b0ob7f2pCkXm4onteWvLE=
|
||||
humungus.tedunangst.com/r/webs v0.6.11 h1:go1OtvHRYveCPtH28vajw1CbdL9whtJyG0+DKn6aQcI=
|
||||
humungus.tedunangst.com/r/webs v0.6.11/go.mod h1:OXm4OzXMNIw95czKlkM51DPFKzgo+jrQ58+pINVWmWE=
|
||||
|
|
5
web.go
5
web.go
|
@ -1296,7 +1296,7 @@ var combocache = cache.New(cache.Options{Filler: func(userid int64) ([]string, b
|
|||
combos = oneofakind(combos)
|
||||
sort.Strings(combos)
|
||||
return combos, true
|
||||
}})
|
||||
}, Invalidator: &honkerinvalidator})
|
||||
|
||||
func showcombos(w http.ResponseWriter, r *http.Request) {
|
||||
userinfo := login.GetUserInfo(r)
|
||||
|
@ -1318,8 +1318,7 @@ func submithonker(w http.ResponseWriter, r *http.Request) {
|
|||
combos = " " + combos + " "
|
||||
honkerid, _ := strconv.ParseInt(r.FormValue("honkerid"), 10, 0)
|
||||
|
||||
defer combocache.Clear(u.UserID)
|
||||
defer shortnames.Clear(u.UserID)
|
||||
defer honkerinvalidator.Clear(u.UserID)
|
||||
|
||||
if honkerid > 0 {
|
||||
goodbye := r.FormValue("goodbye")
|
||||
|
|
Loading…
Reference in New Issue