forked from Kieran/snort
bug: profile loading bugs
This commit is contained in:
parent
39dbfe1183
commit
c515636616
@ -49,19 +49,34 @@ class UserProfileCache extends FeedCache<MetadataCache> {
|
|||||||
*/
|
*/
|
||||||
async update(m: MetadataCache) {
|
async update(m: MetadataCache) {
|
||||||
const existing = this.getFromCache(m.pubkey);
|
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) {
|
if (!existing || existing.created < m.created || refresh) {
|
||||||
// fetch zapper key
|
if (!refresh) {
|
||||||
const lnurl = m.lud16 || m.lud06;
|
// fetch zapper key
|
||||||
if (lnurl) {
|
const lnurl = m.lud16 || m.lud06;
|
||||||
try {
|
if (lnurl) {
|
||||||
const svc = new LNURL(lnurl);
|
try {
|
||||||
await svc.load();
|
const svc = new LNURL(lnurl);
|
||||||
m.zapService = svc.zapperPubkey;
|
await svc.load();
|
||||||
} catch {
|
m.zapService = svc.zapperPubkey;
|
||||||
console.debug("Failed to load LNURL for zapper pubkey", lnurl);
|
} catch {
|
||||||
|
console.debug("Failed to load LNURL for zapper pubkey", lnurl);
|
||||||
|
}
|
||||||
|
// ignored
|
||||||
}
|
}
|
||||||
// ignored
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.cache.set(m.pubkey, m);
|
this.cache.set(m.pubkey, m);
|
||||||
|
@ -50,13 +50,16 @@ class ProfileLoaderService {
|
|||||||
|
|
||||||
const sub = new RequestBuilder(`profiles`);
|
const sub = new RequestBuilder(`profiles`);
|
||||||
sub
|
sub
|
||||||
|
.withOptions({
|
||||||
|
skipDiff: true,
|
||||||
|
})
|
||||||
.withFilter()
|
.withFilter()
|
||||||
.kinds([EventKind.SetMetadata])
|
.kinds([EventKind.SetMetadata])
|
||||||
.authors([...missing]);
|
.authors([...missing]);
|
||||||
|
|
||||||
const q = System.Query<PubkeyReplaceableNoteStore>(PubkeyReplaceableNoteStore, sub);
|
const q = System.Query<PubkeyReplaceableNoteStore>(PubkeyReplaceableNoteStore, sub);
|
||||||
// never release this callback, it will stop firing anyway after eose
|
// 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) {
|
for (const e of ev) {
|
||||||
const profile = mapEventToProfile(e);
|
const profile = mapEventToProfile(e);
|
||||||
if (profile) {
|
if (profile) {
|
||||||
@ -70,8 +73,8 @@ class ProfileLoaderService {
|
|||||||
if (!q.loading) {
|
if (!q.loading) {
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
resolve(q.getSnapshotData() ?? []);
|
resolve(q.getSnapshotData() ?? []);
|
||||||
|
release();
|
||||||
}
|
}
|
||||||
release();
|
|
||||||
});
|
});
|
||||||
timeout = setTimeout(() => {
|
timeout = setTimeout(() => {
|
||||||
release();
|
release();
|
||||||
@ -79,7 +82,6 @@ class ProfileLoaderService {
|
|||||||
}, 5_000);
|
}, 5_000);
|
||||||
});
|
});
|
||||||
|
|
||||||
releaseOnEvent();
|
|
||||||
const couldNotFetch = [...missing].filter(a => !results.some(b => b.pubkey === a));
|
const couldNotFetch = [...missing].filter(a => !results.some(b => b.pubkey === a));
|
||||||
if (couldNotFetch.length > 0) {
|
if (couldNotFetch.length > 0) {
|
||||||
console.debug("No profiles: ", couldNotFetch);
|
console.debug("No profiles: ", couldNotFetch);
|
||||||
|
@ -35,6 +35,10 @@ export interface BuiltRawReqFilter {
|
|||||||
export interface RequestBuilderOptions {
|
export interface RequestBuilderOptions {
|
||||||
leaveOpen?: boolean;
|
leaveOpen?: boolean;
|
||||||
relays?: Array<string>;
|
relays?: Array<string>;
|
||||||
|
/**
|
||||||
|
* Do not apply diff logic and always use full filters for query
|
||||||
|
*/
|
||||||
|
skipDiff?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -218,7 +218,7 @@ export class NostrSystem {
|
|||||||
q.unCancel();
|
q.unCancel();
|
||||||
|
|
||||||
const diff = diffFilters(q.request.filters, filters);
|
const diff = diffFilters(q.request.filters, filters);
|
||||||
if (!diff.changed) {
|
if (!diff.changed && !req.options?.skipDiff) {
|
||||||
this.#changed();
|
this.#changed();
|
||||||
return unwrap(this.Feeds.get(req.id)) as Readonly<T>;
|
return unwrap(this.Feeds.get(req.id)) as Readonly<T>;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user