# HG changeset patch # User Ted Unangst # Date 1717899439 14400 # Sat Jun 08 22:17:19 2024 -0400 # Node ID 9e20e9e47a4b5fb4e944de839ee7c7b7786b3230 # Parent d52a49be6a0256cdbf06269736ba89eac58c70a7 fetch handles async diff --git a/fun.go b/fun.go --- a/fun.go +++ b/fun.go @@ -28,6 +28,7 @@ "regexp" "strconv" "strings" + "sync" "time" "golang.org/x/net/html" @@ -65,8 +66,10 @@ } func reverbolate(userid UserID, honks []*Honk) { + var handlers sync.WaitGroup user, _ := somenumberedusers.Get(userid) - for _, h := range honks { + for i := range honks { + h := honks[i] h.What += "ed" if h.What == "honked" && h.RID != "" { h.What = "honked back" @@ -86,43 +89,47 @@ if local && h.What != "bonked" { h.Noise = re_memes.ReplaceAllString(h.Noise, "") } - h.Username, h.Handle = handles(h.Honker) - if !local { - short := shortname(userid, h.Honker) - if short != "" { - h.Username = short - } else { - h.Username = h.Handle - if len(h.Username) > 20 { - h.Username = h.Username[:20] + ".." - } - } - } - if user != nil { - hset := []string{} - if h.Honker != user.URL { - hset = append(hset, "@"+h.Handle) - } - if user.Options.MentionAll { - for _, a := range h.Audience { - if a == h.Honker || a == user.URL { - continue - } - _, hand := handles(a) - if hand != "" { - hand = "@" + hand - hset = append(hset, hand) + handlers.Add(1) + go func() { + h.Username, h.Handle = handles(h.Honker) + if !local { + short := shortname(userid, h.Honker) + if short != "" { + h.Username = short + } else { + h.Username = h.Handle + if len(h.Username) > 20 { + h.Username = h.Username[:20] + ".." } } } - h.Handles = strings.Join(hset, " ") - } - if h.URL == "" { - h.URL = h.XID - } - if h.Oonker != "" { - _, h.Oondle = handles(h.Oonker) - } + if user != nil { + hset := []string{} + if h.Honker != user.URL { + hset = append(hset, "@"+h.Handle) + } + if user.Options.MentionAll { + for _, a := range h.Audience { + if a == h.Honker || a == user.URL { + continue + } + _, hand := handles(a) + if hand != "" { + hand = "@" + hand + hset = append(hset, hand) + } + } + } + h.Handles = strings.Join(hset, " ") + } + if h.URL == "" { + h.URL = h.XID + } + if h.Oonker != "" { + _, h.Oondle = handles(h.Oonker) + } + handlers.Done() + }() h.Precis = demoji(h.Precis) h.Noise = demoji(h.Noise) h.Open = "open" @@ -201,6 +208,7 @@ } h.Donks = h.Donks[:j] } + handlers.Wait() unsee(honks, userid)