all repos — honk @ 2fd1e75c678f2607b9a2b1a5ba167b2f13b33017

my fork of honk

refresh pages using internal honkid which makes query much faster
Ted Unangst tedu@tedunangst.com
Sun, 20 Oct 2019 14:36:55 -0400
commit

2fd1e75c678f2607b9a2b1a5ba167b2f13b33017

parent

a376b9f6c83e7fe960c7baacd5f7e2882baf55d7

6 files changed, 67 insertions(+), 73 deletions(-)

jump to
M activity.goactivity.go

@@ -1153,7 +1153,7 @@ if honk == nil || !honk.Public {

return nil, true } user, _ := butwhatabout(honk.Username) - rawhonks := gethonksbyconvoy(honk.UserID, honk.Convoy) + rawhonks := gethonksbyconvoy(honk.UserID, honk.Convoy, 0) reversehonks(rawhonks) for _, h := range rawhonks { if h.RID == honk.XID && h.Public && (h.Whofore == 2 || h.IsAcked()) {
M database.godatabase.go

@@ -150,53 +150,53 @@ }

reversehonks(honks) return honks } -func gethonksbyuser(name string, includeprivate bool) []*Honk { +func gethonksbyuser(name string, includeprivate bool, wanted int64) []*Honk { dt := time.Now().UTC().Add(-7 * 24 * time.Hour).Format(dbtimeformat) whofore := 2 if includeprivate { whofore = 3 } - rows, err := stmtUserHonks.Query(whofore, name, dt) + rows, err := stmtUserHonks.Query(wanted, whofore, name, dt) return getsomehonks(rows, err) } -func gethonksforuser(userid int64) []*Honk { +func gethonksforuser(userid int64, wanted int64) []*Honk { dt := time.Now().UTC().Add(-7 * 24 * time.Hour).Format(dbtimeformat) - rows, err := stmtHonksForUser.Query(userid, dt, userid, userid) + rows, err := stmtHonksForUser.Query(wanted, userid, dt, userid, userid) return getsomehonks(rows, err) } -func gethonksforuserfirstclass(userid int64) []*Honk { +func gethonksforuserfirstclass(userid int64, wanted int64) []*Honk { dt := time.Now().UTC().Add(-7 * 24 * time.Hour).Format(dbtimeformat) - rows, err := stmtHonksForUserFirstClass.Query(userid, dt, userid, userid) + rows, err := stmtHonksForUserFirstClass.Query(wanted, userid, dt, userid, userid) return getsomehonks(rows, err) } -func gethonksforme(userid int64) []*Honk { +func gethonksforme(userid int64, wanted int64) []*Honk { dt := time.Now().UTC().Add(-7 * 24 * time.Hour).Format(dbtimeformat) - rows, err := stmtHonksForMe.Query(userid, dt, userid) + rows, err := stmtHonksForMe.Query(wanted, userid, dt, userid) return getsomehonks(rows, err) } -func getsavedhonks(userid int64) []*Honk { - rows, err := stmtHonksISaved.Query(userid) +func getsavedhonks(userid int64, wanted int64) []*Honk { + rows, err := stmtHonksISaved.Query(wanted, userid) return getsomehonks(rows, err) } -func gethonksbyhonker(userid int64, honker string) []*Honk { - rows, err := stmtHonksByHonker.Query(userid, honker, userid) +func gethonksbyhonker(userid int64, honker string, wanted int64) []*Honk { + rows, err := stmtHonksByHonker.Query(wanted, userid, honker, userid) return getsomehonks(rows, err) } -func gethonksbyxonker(userid int64, xonker string) []*Honk { - rows, err := stmtHonksByXonker.Query(userid, xonker, xonker, userid) +func gethonksbyxonker(userid int64, xonker string, wanted int64) []*Honk { + rows, err := stmtHonksByXonker.Query(wanted, userid, xonker, xonker, userid) return getsomehonks(rows, err) } -func gethonksbycombo(userid int64, combo string) []*Honk { +func gethonksbycombo(userid int64, combo string, wanted int64) []*Honk { combo = "% " + combo + " %" - rows, err := stmtHonksByCombo.Query(userid, combo, userid) + rows, err := stmtHonksByCombo.Query(wanted, userid, combo, userid) return getsomehonks(rows, err) } -func gethonksbyconvoy(userid int64, convoy string) []*Honk { - rows, err := stmtHonksByConvoy.Query(userid, userid, convoy) +func gethonksbyconvoy(userid int64, convoy string, wanted int64) []*Honk { + rows, err := stmtHonksByConvoy.Query(wanted, userid, userid, convoy) honks := getsomehonks(rows, err) return honks } -func gethonksbysearch(userid int64, q string) []*Honk { +func gethonksbysearch(userid int64, q string, wanted int64) []*Honk { honker := "" withhonker := 0 site := ""

@@ -225,12 +225,12 @@ }

q += t } q += "%" - rows, err := stmtHonksBySearch.Query(userid, withsite, site, withhonker, honker, honker, q, userid) + rows, err := stmtHonksBySearch.Query(wanted, userid, withsite, site, withhonker, honker, honker, q, userid) honks := getsomehonks(rows, err) return honks } -func gethonksbyontology(userid int64, name string) []*Honk { - rows, err := stmtHonksByOntology.Query(name, userid, userid) +func gethonksbyontology(userid int64, name string, wanted int64) []*Honk { + rows, err := stmtHonksByOntology.Query(wanted, name, userid, userid) honks := getsomehonks(rows, err) return honks }

@@ -667,18 +667,18 @@ stmtAnyXonk = preparetodie(db, selecthonks+"where xid = ? order by honks.honkid asc")

stmtOneBonk = preparetodie(db, selecthonks+"where honks.userid = ? and xid = ? and what = 'bonk' and whofore = 2") stmtPublicHonks = preparetodie(db, selecthonks+"where whofore = 2 and dt > ?"+limit) stmtEventHonks = preparetodie(db, selecthonks+"where (whofore = 2 or honks.userid = ?) and what = 'event'"+limit) - stmtUserHonks = preparetodie(db, selecthonks+"where (whofore = 2 or whofore = ?) and username = ? and dt > ?"+limit) + stmtUserHonks = preparetodie(db, selecthonks+"where honks.honkid > ? and (whofore = 2 or whofore = ?) and username = ? and dt > ?"+limit) myhonkers := " and honker in (select xid from honkers where userid = ? and (flavor = 'sub' or flavor = 'peep' or flavor = 'presub') and combos not like '% - %')" - stmtHonksForUser = preparetodie(db, selecthonks+"where honks.userid = ? and dt > ?"+myhonkers+butnotthose+limit) - stmtHonksForUserFirstClass = preparetodie(db, selecthonks+"where honks.userid = ? and dt > ? and (what <> 'tonk')"+myhonkers+butnotthose+limit) - stmtHonksForMe = preparetodie(db, selecthonks+"where honks.userid = ? and dt > ? and whofore = 1"+butnotthose+limit) - 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 (? = 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) + stmtHonksForUser = preparetodie(db, selecthonks+"where honks.honkid > ? and honks.userid = ? and dt > ?"+myhonkers+butnotthose+limit) + stmtHonksForUserFirstClass = preparetodie(db, selecthonks+"where honks.honkid > ? and honks.userid = ? and dt > ? and (what <> 'tonk')"+myhonkers+butnotthose+limit) + stmtHonksForMe = preparetodie(db, selecthonks+"where honks.honkid > ? and honks.userid = ? and dt > ? and whofore = 1"+butnotthose+limit) + stmtHonksISaved = preparetodie(db, selecthonks+"where honks.honkid > ? and 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.honkid > ? and honks.userid = ? and honkers.name = ?"+butnotthose+limit) + stmtHonksByXonker = preparetodie(db, selecthonks+" where honks.honkid > ? and honks.userid = ? and (honker = ? or oonker = ?)"+butnotthose+limit) + stmtHonksByCombo = preparetodie(db, selecthonks+"join honkers on honkers.xid = honks.honker where honks.honkid > ? and honks.userid = ? and honkers.combos like ?"+butnotthose+limit) + stmtHonksBySearch = preparetodie(db, selecthonks+"where honks.honkid > ? and 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.honkid > ? and (honks.userid = ? or (? = -1 and whofore = 2)) and convoy = ?"+limit) + stmtHonksByOntology = preparetodie(db, selecthonks+"join onts on honks.honkid = onts.honkid where honks.honkid > ? and onts.ontology = ? and (honks.userid = ? or (? = -1 and honks.whofore = 2))"+limit) stmtSaveMeta = preparetodie(db, "insert into honkmeta (honkid, genus, json) values (?, ?, ?)") stmtDeleteMeta = preparetodie(db, "delete from honkmeta where honkid = ? and genus <> ?")
M views/honkfrags.htmlviews/honkfrags.html

@@ -1,4 +1,4 @@

-<div>{{ .TopXID }}</div> +<div>{{ .TopHID }}</div> {{ $BonkCSRF := .HonkCSRF }} <div><p>{{ .ServerMessage }}</div> <div>
M views/honkpage.htmlviews/honkpage.html

@@ -30,8 +30,8 @@ <script>

var csrftoken = {{ .HonkCSRF }} var honksforpage = { } var curpagestate = { name: "{{ .PageName }}", arg : "{{ .PageArg }}" } -var topxid = { } -topxid[curpagestate.name + ":" + curpagestate.arg] = "{{ .TopXID }}" +var tophid = { } +tophid[curpagestate.name + ":" + curpagestate.arg] = "{{ .TopHID }}" var servermsgs = { } servermsgs[curpagestate.name + ":" + curpagestate.arg] = "{{ .ServerMessage }}"
M views/honkpage.jsviews/honkpage.js

@@ -65,7 +65,7 @@ }

function fillinhonks(xhr) { var doc = xhr.responseXML var stash = curpagestate.name + ":" + curpagestate.arg - topxid[stash] = doc.children[0].children[1].children[0].innerText + tophid[stash] = doc.children[0].children[1].children[0].innerText var srvmsg = doc.children[0].children[1].children[1] var honks = doc.children[0].children[1].children[2].children

@@ -118,7 +118,7 @@ btn.innerHTML = "refreshing"

btn.disabled = true var args = hydrargs() var stash = curpagestate.name + ":" + curpagestate.arg - args["topxid"] = topxid[stash] + args["tophid"] = tophid[stash] get("/hydra?" + encode(args), function(xhr) { var lenhonks = fillinhonks(xhr) btn.innerHTML = "refresh"
M web.goweb.go

@@ -100,7 +100,7 @@ switch r.URL.Path {

case "/atme": templinfo["PageName"] = "at me!" templinfo["PageName"] = "atme" - honks = gethonksforme(userid) + honks = gethonksforme(userid, 0) case "/events": templinfo["ServerMessage"] = "some recent and upcoming events" templinfo["PageName"] = "events"

@@ -108,15 +108,15 @@ honks = geteventhonks(userid)

honks = osmosis(honks, userid) case "/first": templinfo["PageName"] = "first" - honks = gethonksforuser(userid) + honks = gethonksforuser(userid, 0) honks = osmosis(honks, userid) case "/saved": templinfo["ServerMessage"] = "saved honks" templinfo["PageName"] = "saved" - honks = getsavedhonks(userid) + honks = getsavedhonks(userid, 0) default: templinfo["PageName"] = "home" - honks = gethonksforuser(userid) + honks = gethonksforuser(userid, 0) honks = osmosis(honks, userid) } templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)

@@ -156,7 +156,7 @@ name := mux.Vars(r)["name"]

var honks []*Honk if name != "" { - honks = gethonksbyuser(name, false) + honks = gethonksbyuser(name, false, 0) } else { honks = getpublichonks() }

@@ -477,7 +477,7 @@ user, err := butwhatabout(name)

if err != nil { return nil, false } - honks := gethonksbyuser(name, false) + honks := gethonksbyuser(name, false, 0) if len(honks) > 20 { honks = honks[0:20] }

@@ -570,7 +570,7 @@ }

return } u := login.GetUserInfo(r) - honks := gethonksbyuser(name, u != nil && u.Username == name) + honks := gethonksbyuser(name, u != nil && u.Username == name, 0) templinfo := getInfo(r) filt := htfilter.New() templinfo["Name"] = user.Name

@@ -588,9 +588,9 @@ name := mux.Vars(r)["name"]

var honks []*Honk if name == "" { name = r.FormValue("xid") - honks = gethonksbyxonker(u.UserID, name) + honks = gethonksbyxonker(u.UserID, name, 0) } else { - honks = gethonksbyhonker(u.UserID, name) + honks = gethonksbyhonker(u.UserID, name, 0) } msg := templates.Sprintf(`honks by honker: <a href="%s" ref="noreferrer">%s</a>`, name, name) templinfo := getInfo(r)

@@ -604,7 +604,7 @@

func showcombo(w http.ResponseWriter, r *http.Request) { name := mux.Vars(r)["name"] u := login.GetUserInfo(r) - honks := gethonksbycombo(u.UserID, name) + honks := gethonksbycombo(u.UserID, name, 0) honks = osmosis(honks, u.UserID) templinfo := getInfo(r) templinfo["PageName"] = "combo"

@@ -616,10 +616,10 @@ }

func showconvoy(w http.ResponseWriter, r *http.Request) { c := r.FormValue("c") u := login.GetUserInfo(r) - honks := gethonksbyconvoy(u.UserID, c) + honks := gethonksbyconvoy(u.UserID, c, 0) templinfo := getInfo(r) if len(honks) > 0 { - templinfo["TopXID"] = honks[0].XID + templinfo["TopHID"] = honks[0].ID } reversehonks(honks) templinfo["PageName"] = "convoy"

@@ -631,7 +631,7 @@ }

func showsearch(w http.ResponseWriter, r *http.Request) { q := r.FormValue("q") u := login.GetUserInfo(r) - honks := gethonksbysearch(u.UserID, q) + honks := gethonksbysearch(u.UserID, q, 0) templinfo := getInfo(r) templinfo["PageName"] = "search" templinfo["PageArg"] = q

@@ -646,7 +646,7 @@ var userid int64 = -1

if u != nil { userid = u.UserID } - honks := gethonksbyontology(userid, "#"+name) + honks := gethonksbyontology(userid, "#"+name, 0) templinfo := getInfo(r) templinfo["ServerMessage"] = "honks by ontology: " + name templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)

@@ -742,7 +742,7 @@ templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r)

honkpage(w, u, []*Honk{honk}, templinfo) return } - rawhonks := gethonksbyconvoy(honk.UserID, honk.Convoy) + rawhonks := gethonksbyconvoy(honk.UserID, honk.Convoy, 0) reversehonks(rawhonks) var honks []*Honk for _, h := range rawhonks {

@@ -767,8 +767,8 @@ w.Header().Set("Cache-Control", "max-age=60")

} reverbolate(userid, honks) templinfo["Honks"] = honks - if templinfo["TopXID"] == nil && len(honks) > 0 { - templinfo["TopXID"] = honks[0].XID + if templinfo["TopHID"] == nil && len(honks) > 0 { + templinfo["TopHID"] = honks[0].ID } err := readviews.Execute(w, "honkpage.html", templinfo) if err != nil {

@@ -1632,54 +1632,48 @@ userid := u.UserID

templinfo := getInfo(r) templinfo["HonkCSRF"] = login.GetCSRF("honkhonk", r) page := r.FormValue("page") + + wanted, _ := strconv.ParseInt(r.FormValue("tophid"), 10, 0) + var honks []*Honk switch page { case "atme": - honks = gethonksforme(userid) + honks = gethonksforme(userid, wanted) templinfo["ServerMessage"] = "at me!" case "home": - honks = gethonksforuser(userid) + honks = gethonksforuser(userid, wanted) honks = osmosis(honks, userid) templinfo["ServerMessage"] = serverMsg case "first": - honks = gethonksforuserfirstclass(userid) + honks = gethonksforuserfirstclass(userid, wanted) honks = osmosis(honks, userid) templinfo["ServerMessage"] = "first class only" case "saved": - honks = getsavedhonks(userid) + honks = getsavedhonks(userid, wanted) templinfo["PageName"] = "saved" templinfo["ServerMessage"] = "saved honks" case "combo": c := r.FormValue("c") - honks = gethonksbycombo(userid, c) + honks = gethonksbycombo(userid, c, wanted) honks = osmosis(honks, userid) templinfo["ServerMessage"] = "honks by combo: " + c case "convoy": c := r.FormValue("c") - honks = gethonksbyconvoy(userid, c) + honks = gethonksbyconvoy(userid, c, wanted) templinfo["ServerMessage"] = "honks in convoy: " + c case "honker": xid := r.FormValue("xid") if strings.IndexByte(xid, '@') != -1 { xid = gofish(xid) } - honks = gethonksbyxonker(userid, xid) + honks = gethonksbyxonker(userid, xid, wanted) msg := templates.Sprintf(`honks by honker: <a href="%s" ref="noreferrer">%s</a>`, xid, xid) templinfo["ServerMessage"] = msg default: http.NotFound(w, r) } if len(honks) > 0 { - templinfo["TopXID"] = honks[0].XID - } - if topxid := r.FormValue("topxid"); topxid != "" { - for i, h := range honks { - if h.XID == topxid { - honks = honks[0:i] - break - } - } - log.Printf("topxid %d frags", len(honks)) + templinfo["TopHID"] = honks[0].ID } reverbolate(userid, honks) templinfo["Honks"] = honks