From c02a97aa6810e91e2ceb341a43d4dc37c38c3364 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Sat, 19 Oct 2019 15:19:04 -0400 Subject: [PATCH 1/4] close file --- web.go | 1 + 1 file changed, 1 insertion(+) diff --git a/web.go b/web.go index 809081f..282de4b 100644 --- a/web.go +++ b/web.go @@ -1565,6 +1565,7 @@ func servecss(w http.ResponseWriter, r *http.Request) { http.NotFound(w, r) return } + defer fd.Close() w.Header().Set("Cache-Control", "max-age=0") w.Header().Set("Content-Type", "text/css; charset=utf-8") err = css.Filter(fd, w) From c7581239337242c7a5f22071cbcd49788e508423 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Sat, 19 Oct 2019 15:20:47 -0400 Subject: [PATCH 2/4] slightly simpler --- web.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/web.go b/web.go index 282de4b..1e73426 100644 --- a/web.go +++ b/web.go @@ -1534,13 +1534,11 @@ func fingerlicker(w http.ResponseWriter, r *http.Request) { j := junk.New() j["subject"] = fmt.Sprintf("acct:%s@%s", user.Name, serverName) j["aliases"] = []string{user.URL} - var links []junk.Junk l := junk.New() l["rel"] = "self" l["type"] = `application/activity+json` l["href"] = user.URL - links = append(links, l) - j["links"] = links + j["links"] = []junk.Junk{l} w.Header().Set("Cache-Control", "max-age=3600") w.Header().Set("Content-Type", "application/jrd+json") From 3de799b34caf3d6ff7fc9e1f11e20225a9e508e8 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Sat, 19 Oct 2019 15:26:36 -0400 Subject: [PATCH 3/4] remove some extra variables --- activity.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/activity.go b/activity.go index 9992cb2..da57ca0 100644 --- a/activity.go +++ b/activity.go @@ -1061,8 +1061,7 @@ func jonkjonk(user *WhatAbout, h *Honk) (junk.Junk, junk.Junk) { } var tags []junk.Junk - g := bunchofgrapes(h.Noise) - for _, m := range g { + for _, m := range bunchofgrapes(h.Noise) { t := junk.New() t["type"] = "Mention" t["name"] = m.who @@ -1077,8 +1076,7 @@ func jonkjonk(user *WhatAbout, h *Honk) (junk.Junk, junk.Junk) { t["name"] = o tags = append(tags, t) } - herd := herdofemus(h.Noise) - for _, e := range herd { + for _, e := range herdofemus(h.Noise) { t := junk.New() t["id"] = e.ID t["type"] = "Emoji" From ec15e6041a7e1b55b7429e48275ed275acf9ef13 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Sat, 19 Oct 2019 15:37:33 -0400 Subject: [PATCH 4/4] rewrite oneofakind with map since we're starting to see longer arrays --- fun.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/fun.go b/fun.go index 1a284ee..97c1929 100644 --- a/fun.go +++ b/fun.go @@ -538,18 +538,17 @@ func firstclass(honk *Honk) bool { } func oneofakind(a []string) []string { - var x []string - for n, s := range a { - if s != "" { - x = append(x, s) - for i := n + 1; i < len(a); i++ { - if a[i] == s { - a[i] = "" - } - } + seen := make(map[string]bool) + seen[""] = true + j := 0 + for _, s := range a { + if !seen[s] { + seen[s] = true + a[j] = s + j++ } } - return x + return a[:j] } var ziggies = make(map[string]*rsa.PrivateKey)