# HG changeset patch # User Ted Unangst # Date 1717902923 14400 # Sat Jun 08 23:15:23 2024 -0400 # Node ID fc3ed639f217c6db794691e460d31d2a99a8d254 # Parent b4d80bf72b6202618463d82981d6f7befaa0968d try assembling boxes async diff --git a/activity.go b/activity.go --- a/activity.go +++ b/activity.go @@ -28,6 +28,7 @@ "os" "regexp" "strings" + "sync" "time" "humungus.tedunangst.com/r/webs/gate" @@ -1650,21 +1651,33 @@ 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 @@ 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 @@ 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 @@ 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 diff --git a/deliverator.go b/deliverator.go --- a/deliverator.go +++ b/deliverator.go @@ -139,8 +139,8 @@ 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 diff --git a/web.go b/web.go --- a/web.go +++ b/web.go @@ -362,8 +362,8 @@ 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 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 }