all repos — honk @ dde64078ade88eece871ef0b5914bdad5056562f

my fork of honk

modestly better search, with parameters
Ted Unangst tedu@tedunangst.com
Tue, 15 Oct 2019 23:27:30 -0400
commit

dde64078ade88eece871ef0b5914bdad5056562f

parent

2d8c06c55c737d969aa0b7df8923daef6a47d53a

5 files changed, 59 insertions(+), 14 deletions(-)

jump to
M database.godatabase.go

@@ -52,6 +52,8 @@ }

return user, nil } +var honkerinvalidator cache.Invalidator + func gethonkers(userid int64) []*Honker { rows, err := stmtHonkers.Query(userid) if err != nil {

@@ -195,8 +197,35 @@ honks := getsomehonks(rows, err)

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 @@ stmtHonksISaved = preparetodie(db, selecthonks+"where honks.userid = ? and flags & 4 order by honks.honkid desc")

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)
M fun.gofun.go

@@ -350,10 +350,9 @@ if m[len(m)-1] == ' ' {

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,13 +372,31 @@ for _, h := range honkers {

m[h.XID] = h.Name } return m, true -}}) +}, Invalidator: &honkerinvalidator}) func shortname(userid int64, xid string) string { var m map[string]string ok := shortnames.Get(userid, &m) if ok { return m[xid] + } + 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 "" }
M go.modgo.mod

@@ -7,7 +7,7 @@ github.com/mattn/go-runewidth v0.0.4

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
M go.sumgo.sum

@@ -21,5 +21,5 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

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=
M web.goweb.go

@@ -1296,7 +1296,7 @@ }

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 @@ combos := strings.TrimSpace(r.FormValue("combos"))

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")