all repos — honk @ 77e857268558d51d9132fb3d0f8d21bb594414f0

my fork of honk

can cache outbox for a bit
Ted Unangst tedu@tedunangst.com
Mon, 07 Oct 2019 18:11:35 -0400
commit

77e857268558d51d9132fb3d0f8d21bb594414f0

parent

5f581e0167c9b9f9d661c0fdf529a88e1ed551e0

1 files changed, 26 insertions(+), 11 deletions(-)

jump to
M web.goweb.go

@@ -455,18 +455,11 @@ log.Print(err)

} } -func outbox(w http.ResponseWriter, r *http.Request) { - name := mux.Vars(r)["name"] +var oldoutbox = cacheNew(cacheOptions{ Filler: func(name string) ([]byte, bool) { user, err := butwhatabout(name) if err != nil { - http.NotFound(w, r) - return + return nil, false } - if stealthmode(user.ID, r) { - http.NotFound(w, r) - return - } - honks := gethonksbyuser(name, false) if len(honks) > 20 { honks = honks[0:20]

@@ -485,8 +478,30 @@ j["type"] = "OrderedCollection"

j["totalItems"] = len(jonks) j["orderedItems"] = jonks - w.Header().Set("Content-Type", theonetruename) - j.Write(w) + var buf bytes.Buffer + j.Write(&buf) + return buf.Bytes(), true +}, Duration: 1*time.Minute}) + +func outbox(w http.ResponseWriter, r *http.Request) { + name := mux.Vars(r)["name"] + user, err := butwhatabout(name) + if err != nil { + http.NotFound(w, r) + return + } + if stealthmode(user.ID, r) { + http.NotFound(w, r) + return + } + var j []byte + ok := oldoutbox.Get(name, &j) + if ok { + w.Header().Set("Content-Type", theonetruename) + w.Write(j) + } else { + http.NotFound(w, r) + } } func emptiness(w http.ResponseWriter, r *http.Request) {