9e20e9e47a4b — Ted Unangst 2 months ago
fetch handles async
1 files changed, 43 insertions(+), 35 deletions(-)

M fun.go
M fun.go +43 -35
@@ 28,6 28,7 @@ import (
 	"regexp"
 	"strconv"
 	"strings"
+	"sync"
 	"time"
 
 	"golang.org/x/net/html"

          
@@ 65,8 66,10 @@ func loadLingo() {
 }
 
 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 @@ func reverbolate(userid UserID, honks []
 		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 @@ func reverbolate(userid UserID, honks []
 		}
 		h.Donks = h.Donks[:j]
 	}
+	handlers.Wait()
 
 	unsee(honks, userid)