From afd0f8f56693f2f3ad302ca4193c89afd9385bba Mon Sep 17 00:00:00 2001 From: Barry Deen Date: Fri, 6 Sep 2024 13:24:33 -0400 Subject: [PATCH] get profile metadata --- main.go | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 4cfb350..0d46fc5 100644 --- a/main.go +++ b/main.go @@ -47,7 +47,7 @@ func main() { panic(err) } - go refreshTrustNetwork() + go refreshTrustNetwork(relay) go archiveTrustedNotes(relay) relay.StoreEvent = append(relay.StoreEvent, db.SaveEvent) @@ -112,9 +112,9 @@ func getEnv(key string) string { return value } -func refreshTrustNetwork() []string { +func refreshTrustNetwork(relay *khatru.Relay) []string { ctx := context.Background() - ticker := time.NewTicker(1 * time.Minute) + ticker := time.NewTicker(1 * time.Hour) for range ticker.C { timeoutCtx, cancel := context.WithTimeout(ctx, 1*time.Second) @@ -131,8 +131,6 @@ func refreshTrustNetwork() []string { } } - fmt.Println("trust network size:", len(trustNetwork)) - chunks := make([][]string, 0) for i := 0; i < len(trustNetwork); i += 100 { end := i + 100 @@ -163,11 +161,38 @@ func refreshTrustNetwork() []string { } fmt.Println("trust network size:", len(trustNetwork)) + getTrustNetworkProfileMetadata(relay) } return trustNetwork } +func getTrustNetworkProfileMetadata(relay *khatru.Relay) { + ctx := context.Background() + + chunks := make([][]string, 0) + for i := 0; i < len(trustNetwork); i += 100 { + end := i + 100 + if end > len(trustNetwork) { + end = len(trustNetwork) + } + chunks = append(chunks, trustNetwork[i:end]) + } + + for _, chunk := range chunks { + timeoutCtx, cancel := context.WithTimeout(ctx, 3*time.Second) + defer cancel() + filters := []nostr.Filter{{ + Authors: chunk, + Kinds: []int{nostr.KindProfileMetadata}, + }} + + for ev := range pool.SubManyEose(timeoutCtx, relays, filters) { + relay.AddEvent(timeoutCtx, ev.Event) + } + } +} + func appendPubkey(pubkey string) { mu.Lock() defer mu.Unlock()