refresh pages using internal honkid which makes query much faster
This commit is contained in:
parent
0a262dbc96
commit
c0d7cee48d
|
@ -1153,7 +1153,7 @@ var oldjonks = cache.New(cache.Options{Filler: func(xid string) ([]byte, bool) {
|
|||
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()) {
|
||||
|
|
66
database.go
66
database.go
|
@ -150,53 +150,53 @@ func geteventhonks(userid int64) []*Honk {
|
|||
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 @@ func gethonksbysearch(userid int64, q string) []*Honk {
|
|||
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 @@ func prepareStatements(db *sql.DB) {
|
|||
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 <> ?")
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
<div>{{ .TopXID }}</div>
|
||||
<div>{{ .TopHID }}</div>
|
||||
{{ $BonkCSRF := .HonkCSRF }}
|
||||
<div><p>{{ .ServerMessage }}</div>
|
||||
<div>
|
||||
|
|
|
@ -30,8 +30,8 @@
|
|||
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 }}"
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ function flogit(el, how, xid) {
|
|||
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 @@ function refreshhonks(btn) {
|
|||
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"
|
||||
|
|
62
web.go
62
web.go
|
@ -100,7 +100,7 @@ func homepage(w http.ResponseWriter, r *http.Request) {
|
|||
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 @@ func homepage(w http.ResponseWriter, r *http.Request) {
|
|||
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 @@ func showrss(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
var honks []*Honk
|
||||
if name != "" {
|
||||
honks = gethonksbyuser(name, false)
|
||||
honks = gethonksbyuser(name, false, 0)
|
||||
} else {
|
||||
honks = getpublichonks()
|
||||
}
|
||||
|
@ -477,7 +477,7 @@ var oldoutbox = cache.New(cache.Options{Filler: func(name string) ([]byte, bool)
|
|||
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 @@ func showuser(w http.ResponseWriter, r *http.Request) {
|
|||
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 @@ func showhonker(w http.ResponseWriter, r *http.Request) {
|
|||
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 showhonker(w http.ResponseWriter, r *http.Request) {
|
|||
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 showcombo(w http.ResponseWriter, r *http.Request) {
|
|||
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 showconvoy(w http.ResponseWriter, r *http.Request) {
|
|||
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 @@ func showontology(w http.ResponseWriter, r *http.Request) {
|
|||
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 @@ func showhonk(w http.ResponseWriter, r *http.Request) {
|
|||
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 @@ func honkpage(w http.ResponseWriter, u *login.UserInfo, honks []*Honk, templinfo
|
|||
}
|
||||
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 @@ func webhydra(w http.ResponseWriter, r *http.Request) {
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue