From c51563661644c26d60ed6b3ab81ce8774a637013 Mon Sep 17 00:00:00 2001 From: Kieran Date: Tue, 4 Apr 2023 15:27:49 +0100 Subject: [PATCH] bug: profile loading bugs --- packages/app/src/Cache/UserCache.ts | 37 ++++++++++++++++------- packages/app/src/System/ProfileCache.ts | 8 +++-- packages/app/src/System/RequestBuilder.ts | 4 +++ packages/app/src/System/index.ts | 2 +- 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/packages/app/src/Cache/UserCache.ts b/packages/app/src/Cache/UserCache.ts index a504030..e4a2cf5 100644 --- a/packages/app/src/Cache/UserCache.ts +++ b/packages/app/src/Cache/UserCache.ts @@ -49,19 +49,34 @@ class UserProfileCache extends FeedCache { */ async update(m: MetadataCache) { const existing = this.getFromCache(m.pubkey); - const refresh = existing && existing.created === m.created && existing.loaded < m.loaded; + const refresh = existing && existing.loaded < m.loaded; + const updateType = (() => { + if (!existing) { + return "new_profile"; + } + if (existing.created < m.created) { + return "updated_profile"; + } + if (refresh) { + return "refresh_profile"; + } + return "no_change"; + })(); + console.debug(`Updating ${m.pubkey} ${updateType}`, m); if (!existing || existing.created < m.created || refresh) { - // fetch zapper key - const lnurl = m.lud16 || m.lud06; - if (lnurl) { - try { - const svc = new LNURL(lnurl); - await svc.load(); - m.zapService = svc.zapperPubkey; - } catch { - console.debug("Failed to load LNURL for zapper pubkey", lnurl); + if (!refresh) { + // fetch zapper key + const lnurl = m.lud16 || m.lud06; + if (lnurl) { + try { + const svc = new LNURL(lnurl); + await svc.load(); + m.zapService = svc.zapperPubkey; + } catch { + console.debug("Failed to load LNURL for zapper pubkey", lnurl); + } + // ignored } - // ignored } this.cache.set(m.pubkey, m); diff --git a/packages/app/src/System/ProfileCache.ts b/packages/app/src/System/ProfileCache.ts index a0379b0..29bec0a 100644 --- a/packages/app/src/System/ProfileCache.ts +++ b/packages/app/src/System/ProfileCache.ts @@ -50,13 +50,16 @@ class ProfileLoaderService { const sub = new RequestBuilder(`profiles`); sub + .withOptions({ + skipDiff: true, + }) .withFilter() .kinds([EventKind.SetMetadata]) .authors([...missing]); const q = System.Query(PubkeyReplaceableNoteStore, sub); // never release this callback, it will stop firing anyway after eose - const releaseOnEvent = q.onEvent(async ev => { + q.onEvent(async ev => { for (const e of ev) { const profile = mapEventToProfile(e); if (profile) { @@ -70,8 +73,8 @@ class ProfileLoaderService { if (!q.loading) { clearTimeout(timeout); resolve(q.getSnapshotData() ?? []); + release(); } - release(); }); timeout = setTimeout(() => { release(); @@ -79,7 +82,6 @@ class ProfileLoaderService { }, 5_000); }); - releaseOnEvent(); const couldNotFetch = [...missing].filter(a => !results.some(b => b.pubkey === a)); if (couldNotFetch.length > 0) { console.debug("No profiles: ", couldNotFetch); diff --git a/packages/app/src/System/RequestBuilder.ts b/packages/app/src/System/RequestBuilder.ts index f296f1a..63a66f2 100644 --- a/packages/app/src/System/RequestBuilder.ts +++ b/packages/app/src/System/RequestBuilder.ts @@ -35,6 +35,10 @@ export interface BuiltRawReqFilter { export interface RequestBuilderOptions { leaveOpen?: boolean; relays?: Array; + /** + * Do not apply diff logic and always use full filters for query + */ + skipDiff?: boolean; } /** diff --git a/packages/app/src/System/index.ts b/packages/app/src/System/index.ts index 37a2793..1e59ae9 100644 --- a/packages/app/src/System/index.ts +++ b/packages/app/src/System/index.ts @@ -218,7 +218,7 @@ export class NostrSystem { q.unCancel(); const diff = diffFilters(q.request.filters, filters); - if (!diff.changed) { + if (!diff.changed && !req.options?.skipDiff) { this.#changed(); return unwrap(this.Feeds.get(req.id)) as Readonly; } else {