From 0c2f669017f7b767d7b08c086dd59ea53ec9bbba Mon Sep 17 00:00:00 2001 From: Kieran Date: Mon, 19 Jun 2023 10:17:09 +0100 Subject: [PATCH] feat: use metadata relays for missing profiles --- packages/system/src/ProfileCache.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/system/src/ProfileCache.ts b/packages/system/src/ProfileCache.ts index 9fefe90b6..7fd8b5d4b 100644 --- a/packages/system/src/ProfileCache.ts +++ b/packages/system/src/ProfileCache.ts @@ -5,10 +5,20 @@ import { EventKind, HexKey, SystemInterface, TaggedRawEvent, PubkeyReplaceableNo import { ProfileCacheExpire } from "./Const"; import { mapEventToProfile, MetadataCache } from "./cache"; +const MetadataRelays = [ + "wss://purplepag.es" +] + export class ProfileLoaderService { #system: SystemInterface; #cache: FeedCache; + /** + * A set of pubkeys we could not find last run, + * This list will attempt to use known profile metadata relays + */ + #missingLastRun: Set = new Set(); + /** * List of pubkeys to fetch metadata for */ @@ -77,6 +87,12 @@ export class ProfileLoaderService { .kinds([EventKind.SetMetadata]) .authors([...missing]); + if (this.#missingLastRun.size > 0) { + const fMissing = sub.withFilter() + .kinds([EventKind.SetMetadata]) + .authors([...this.#missingLastRun]); + MetadataRelays.forEach(r => fMissing.relay(r)); + } const newProfiles = new Set(); const q = this.#system.Query(PubkeyReplaceableNoteStore, sub); const feed = (q?.feed as PubkeyReplaceableNoteStore) ?? new PubkeyReplaceableNoteStore(); @@ -106,6 +122,7 @@ export class ProfileLoaderService { releaseOnEvent(); const couldNotFetch = [...missing].filter(a => !results.some(b => b.pubkey === a)); + this.#missingLastRun = new Set(couldNotFetch); if (couldNotFetch.length > 0) { this.#log("No profiles: %o", couldNotFetch); const empty = couldNotFetch.map(a =>