fc3ed639f217 — Ted Unangst 2 months ago
try assembling boxes async
3 files changed, 35 insertions(+), 34 deletions(-)

M activity.go
M deliverator.go
M web.go
M activity.go +29 -28
@@ 28,6 28,7 @@ import (
 	"os"
 	"regexp"
 	"strings"
+	"sync"
 	"time"
 
 	"humungus.tedunangst.com/r/webs/gate"

          
@@ 1650,21 1651,33 @@ func gimmejonk(xid string) ([]byte, bool
 
 func boxuprcpts(user *WhatAbout, addresses []string, useshared bool) map[string]bool {
 	rcpts := make(map[string]bool)
-	for _, a := range addresses {
+	var wg sync.WaitGroup
+	var mtx sync.Mutex
+	for i := range addresses {
+		a := addresses[i]
 		if a == "" || a == thewholeworld || a == user.URL || strings.HasSuffix(a, "/followers") {
 			continue
 		}
 		if a[0] == '%' {
+			mtx.Lock()
 			rcpts[a] = true
+			mtx.Unlock()
 			continue
 		}
-		box, ok := boxofboxes.Get(a)
-		if ok && useshared && box.Shared != "" {
-			rcpts["%"+box.Shared] = true
-		} else {
-			rcpts[a] = true
-		}
+		wg.Add(1)
+		go func() {
+			box, _ := boxofboxes.Get(a)
+			mtx.Lock()
+			if box != nil && useshared && box.Shared != "" {
+				rcpts["%"+box.Shared] = true
+			} else {
+				rcpts[a] = true
+			}
+			mtx.Unlock()
+			wg.Done()
+		}()
 	}
+	wg.Wait()
 	return rcpts
 }
 

          
@@ 1739,35 1752,23 @@ func honkworldwide(user *WhatAbout, honk
 	jonk["@context"] = itiswhatitis
 	msg := jonk.ToBytes()
 
-	rcpts := boxuprcpts(user, honk.Audience, honk.Public)
+	aud := honk.Audience
 
 	if honk.Public {
 		for _, h := range getdubs(user.ID) {
 			if h.XID == user.URL {
 				continue
 			}
-			box, ok := boxofboxes.Get(h.XID)
-			if ok && box.Shared != "" {
-				rcpts["%"+box.Shared] = true
-			} else {
-				rcpts[h.XID] = true
-			}
+			aud = append(aud, h.XID)
 		}
 		if honk.What == "update" {
 			for _, f := range getbacktracks(honk.XID) {
-				if f[0] == '%' {
-					rcpts[f] = true
-				} else {
-					box, ok := boxofboxes.Get(f)
-					if ok && box.Shared != "" {
-						rcpts["%"+box.Shared] = true
-					} else {
-						rcpts[f] = true
-					}
-				}
+				aud = append(aud, f)
 			}
 		}
 	}
+	rcpts := boxuprcpts(user, aud, honk.Public)
+
 	for a := range rcpts {
 		go deliverate(user.ID, a, msg)
 	}

          
@@ 1792,8 1793,8 @@ func collectiveaction(honk *Honk) {
 		j["target"] = serverURL("/o/%s", ont[1:])
 		rcpts := make(map[string]bool)
 		for _, dub := range dubs {
-			box, ok := boxofboxes.Get(dub.XID)
-			if ok && box.Shared != "" {
+			box, _ := boxofboxes.Get(dub.XID)
+			if box != nil && box.Shared != "" {
 				rcpts["%"+box.Shared] = true
 			} else {
 				rcpts[dub.XID] = true

          
@@ 2103,8 2104,8 @@ func updateMe(username string) {
 		if f.XID == user.URL {
 			continue
 		}
-		box, ok := boxofboxes.Get(f.XID)
-		if ok && box.Shared != "" {
+		box, _ := boxofboxes.Get(f.XID)
+		if box != nil && box.Shared != "" {
 			rcpts["%"+box.Shared] = true
 		} else {
 			rcpts[f.XID] = true

          
M deliverator.go +2 -2
@@ 139,8 139,8 @@ func deliveration(doover Doover) {
 	if rcpt[0] == '%' {
 		inbox = rcpt[1:]
 	} else {
-		box, ok := boxofboxes.Get(rcpt)
-		if !ok {
+		box, _ := boxofboxes.Get(rcpt)
+		if box == nil {
 			ilog.Printf("failed getting inbox for %s", rcpt)
 			if doover.Tries < nearlyDead {
 				doover.Tries = nearlyDead

          
M web.go +4 -4
@@ 362,8 362,8 @@ func ping(user *WhatAbout, who string) {
 		ilog.Printf("nobody to ping!")
 		return
 	}
-	box, ok := boxofboxes.Get(who)
-	if !ok {
+	box, _ := boxofboxes.Get(who)
+	if box == nil {
 		ilog.Printf("no inbox to ping %s", who)
 		return
 	}

          
@@ 387,8 387,8 @@ func ping(user *WhatAbout, who string) {
 }
 
 func pong(user *WhatAbout, who string, obj string) {
-	box, ok := boxofboxes.Get(who)
-	if !ok {
+	box, _ := boxofboxes.Get(who)
+	if box == nil {
 		ilog.Printf("no inbox to pong %s", who)
 		return
 	}