cache jonks for AP fetches
Ted Unangst tedu@tedunangst.com
Mon, 07 Oct 2019 15:22:10 -0400
3 files changed,
44 insertions(+),
15 deletions(-)
M
activity.go
→
activity.go
@@ -1101,6 +1101,33 @@
return j, jo } +var oldjonks = cacheNew(cacheOptions{Filler: func(xid string) ([]byte, bool) { + row := stmtAnyXonk.QueryRow(xid) + honk := scanhonk(row) + if honk == nil || !honk.Public { + return nil, true + } + user, _ := butwhatabout(honk.Username) + rawhonks := gethonksbyconvoy(honk.UserID, honk.Convoy) + for _, h := range rawhonks { + if h.RID == honk.XID && h.Public && (h.Whofore == 2 || h.IsAcked()) { + honk.Replies = append(honk.Replies, h) + } + } + donksforhonks([]*Honk{honk}) + _, j := jonkjonk(user, honk) + j["@context"] = itiswhatitis + var buf bytes.Buffer + j.Write(&buf) + return buf.Bytes(), true +}}) + +func gimmejonk(xid string) ([]byte, bool) { + var j []byte + ok := oldjonks.Get(xid, &j) + return j, ok +} + func honkworldwide(user *WhatAbout, honk *Honk) { jonk, _ := jonkjonk(user, honk) jonk["@context"] = itiswhatitis
M
database.go
→
database.go
@@ -509,7 +509,7 @@ }
} var stmtHonkers, stmtDubbers, stmtSaveHonker, stmtUpdateFlavor, stmtUpdateHonker *sql.Stmt -var stmtOneXonk, stmtPublicHonks, stmtUserHonks, stmtHonksByCombo, stmtHonksByConvoy *sql.Stmt +var stmtAnyXonk, stmtOneXonk, stmtPublicHonks, stmtUserHonks, stmtHonksByCombo, stmtHonksByConvoy *sql.Stmt var stmtHonksByOntology, stmtHonksForUser, stmtHonksForMe, stmtSaveDub, stmtHonksByXonker *sql.Stmt var stmtHonksBySearch, stmtHonksByHonker, stmtSaveHonk, stmtWhatAbout *sql.Stmt var stmtOneBonk, stmtFindZonk, stmtFindXonk, stmtSaveDonk *sql.Stmt@@ -541,6 +541,7 @@ selecthonks := "select honks.honkid, honks.userid, username, what, honker, oonker, honks.xid, rid, dt, url, audience, noise, precis, format, convoy, whofore, flags from honks join users on honks.userid = users.userid "
limit := " order by honks.honkid desc limit 250" butnotthose := " and convoy not in (select name from zonkers where userid = ? and wherefore = 'zonvoy' order by zonkerid desc limit 100)" stmtOneXonk = preparetodie(db, selecthonks+"where honks.userid = ? and xid = ?") + 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) stmtUserHonks = preparetodie(db, selecthonks+"where (whofore = 2 or whofore = ?) and username = ? and dt > ?"+limit)
M
web.go
→
web.go
@@ -659,8 +659,18 @@ if stealthmode(user.ID, r) {
http.NotFound(w, r) return } + xid := fmt.Sprintf("https://%s%s", serverName, r.URL.Path) - xid := fmt.Sprintf("https://%s%s", serverName, r.URL.Path) + if friendorfoe(r.Header.Get("Accept")) { + j, ok := gimmejonk(xid) + if ok { + w.Header().Set("Content-Type", theonetruename) + w.Write(j) + } else { + http.NotFound(w, r) + } + return + } honk := getxonk(user.ID, xid) if honk == nil { http.NotFound(w, r)@@ -683,19 +693,6 @@ honkpage(w, u, []*Honk{honk}, templinfo)
return } rawhonks := gethonksbyconvoy(honk.UserID, honk.Convoy) - if friendorfoe(r.Header.Get("Accept")) { - for _, h := range rawhonks { - if h.RID == honk.XID && h.Public && (h.Whofore == 2 || h.IsAcked()) { - honk.Replies = append(honk.Replies, h) - } - } - donksforhonks([]*Honk{honk}) - _, j := jonkjonk(user, honk) - j["@context"] = itiswhatitis - w.Header().Set("Content-Type", theonetruename) - j.Write(w) - return - } var honks []*Honk for _, h := range rawhonks { if h.Public && (h.Whofore == 2 || h.IsAcked()) {@@ -815,6 +812,9 @@ wherefore := r.FormValue("wherefore")
what := r.FormValue("what") userinfo := login.GetUserInfo(r) user, _ := butwhatabout(userinfo.Username) + + // my hammer is too big, oh well + defer oldjonks.Flush() if wherefore == "ack" { xonk := getxonk(userinfo.UserID, what)@@ -1127,6 +1127,7 @@ }
if updatexid != "" { updatehonk(honk) + oldjonks.Clear(honk.XID) } else { err := savehonk(honk) if err != nil {