cache followers collection too to reduce garbage

This commit is contained in:
Ted Unangst 2019-11-10 17:01:28 -05:00
parent c0e8e1d74a
commit ed682de765
1 changed files with 24 additions and 13 deletions

37
web.go
View File

@ -651,6 +651,23 @@ func outbox(w http.ResponseWriter, r *http.Request) {
}
}
var oldempties = cache.New(cache.Options{Filler: func(url string) ([]byte, bool) {
colname := "/followers"
if strings.HasSuffix(url, "/following") {
colname = "/following"
}
user := fmt.Sprintf("https://%s%s", serverName, url[:len(url)-10])
j := junk.New()
j["@context"] = itiswhatitis
j["id"] = user + colname
j["attributedTo"] = user
j["type"] = "OrderedCollection"
j["totalItems"] = 0
j["orderedItems"] = []junk.Junk{}
return j.ToBytes(), true
}})
func emptiness(w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]
user, err := butwhatabout(name)
@ -662,20 +679,14 @@ func emptiness(w http.ResponseWriter, r *http.Request) {
http.NotFound(w, r)
return
}
colname := "/followers"
if strings.HasSuffix(r.URL.Path, "/following") {
colname = "/following"
}
j := junk.New()
j["@context"] = itiswhatitis
j["id"] = user.URL + colname
j["attributedTo"] = user.URL
j["type"] = "OrderedCollection"
j["totalItems"] = 0
j["orderedItems"] = []junk.Junk{}
var j []byte
ok := oldempties.Get(r.URL.Path, &j)
if ok {
w.Header().Set("Content-Type", theonetruename)
j.Write(w)
w.Write(j)
} else {
http.NotFound(w, r)
}
}
func showuser(w http.ResponseWriter, r *http.Request) {