Improve loading, including crucial bug preventing merged subscriptions from completing

This commit is contained in:
Jon Staab
2024-09-06 15:54:52 -07:00
parent df3efdee59
commit 3d2e98aacc
7 changed files with 23 additions and 13 deletions
+5 -2
View File
@@ -5,6 +5,7 @@ import {deriveEventsMapped, withGetter} from '@welshman/store'
import {repository, load} from './core' import {repository, load} from './core'
import {collection} from './collection' import {collection} from './collection'
import {ensurePlaintext} from './plaintext' import {ensurePlaintext} from './plaintext'
import {loadRelaySelections} from './relaySelections'
export const follows = withGetter( export const follows = withGetter(
deriveEventsMapped<PublishedList>(repository, { deriveEventsMapped<PublishedList>(repository, {
@@ -27,6 +28,8 @@ export const {
name: "follows", name: "follows",
store: follows, store: follows,
getKey: follows => follows.event.pubkey, getKey: follows => follows.event.pubkey,
load: (pubkey: string, request: Partial<SubscribeRequest> = {}) => load: async (pubkey: string, request: Partial<SubscribeRequest> = {}) => {
load({...request, filters: [{kinds: [FOLLOWS], authors: [pubkey]}]}), await loadRelaySelections(pubkey, request)
await load({...request, filters: [{kinds: [FOLLOWS], authors: [pubkey]}]})
},
}) })
+3 -3
View File
@@ -1,7 +1,7 @@
import {writable, derived} from 'svelte/store' import {writable, derived} from 'svelte/store'
import {withGetter} from '@welshman/store' import {withGetter} from '@welshman/store'
import {type SubscribeRequest} from "@welshman/net" import {type SubscribeRequest} from "@welshman/net"
import {ctx, fetchJson, uniq, batcher, postJson, last} from '@welshman/lib' import {ctx, tryCatch, fetchJson, uniq, batcher, postJson, last} from '@welshman/lib'
import {collection} from './collection' import {collection} from './collection'
import {deriveProfile} from './profiles' import {deriveProfile} from './profiles'
@@ -49,14 +49,14 @@ export const fetchHandles = async (nip05s: string[]) => {
// Use dufflepud if we it's set up to protect user privacy, otherwise fetch directly // Use dufflepud if we it's set up to protect user privacy, otherwise fetch directly
if (base) { if (base) {
const res: any = await postJson(`${base}/handle/info`, {handles: nip05s}) const res: any = await tryCatch(async () => await postJson(`${base}/handle/info`, {handles: nip05s}))
for (const {handle: nip05, info} of res?.data || []) { for (const {handle: nip05, info} of res?.data || []) {
handlesByNip05.set(nip05, info) handlesByNip05.set(nip05, info)
} }
} else { } else {
const results = await Promise.all( const results = await Promise.all(
nip05s.map(async nip05 => ({nip05, info: await queryProfile(nip05)})) nip05s.map(async nip05 => ({nip05, info: await tryCatch(async () => await queryProfile(nip05))}))
) )
for (const {nip05, info} of results) { for (const {nip05, info} of results) {
+5 -2
View File
@@ -5,6 +5,7 @@ import {deriveEventsMapped, withGetter} from '@welshman/store'
import {repository, load} from './core' import {repository, load} from './core'
import {collection} from './collection' import {collection} from './collection'
import {ensurePlaintext} from './plaintext' import {ensurePlaintext} from './plaintext'
import {loadRelaySelections} from './relaySelections'
export const mutes = withGetter( export const mutes = withGetter(
deriveEventsMapped<PublishedList>(repository, { deriveEventsMapped<PublishedList>(repository, {
@@ -27,6 +28,8 @@ export const {
name: "mutes", name: "mutes",
store: mutes, store: mutes,
getKey: mute => mute.event.pubkey, getKey: mute => mute.event.pubkey,
load: (pubkey: string, request: Partial<SubscribeRequest> = {}) => load: async (pubkey: string, request: Partial<SubscribeRequest> = {}) => {
load({...request, filters: [{kinds: [MUTES], authors: [pubkey]}]}), await loadRelaySelections(pubkey, request)
await load({...request, filters: [{kinds: [MUTES], authors: [pubkey]}]})
},
}) })
+5 -2
View File
@@ -6,6 +6,7 @@ import {deriveEventsMapped, withGetter} from '@welshman/store'
import {repository, load} from './core' import {repository, load} from './core'
import {createSearch} from './util' import {createSearch} from './util'
import {collection} from './collection' import {collection} from './collection'
import {loadRelaySelections} from './relaySelections'
export const profiles = withGetter( export const profiles = withGetter(
deriveEventsMapped<PublishedProfile>(repository, { deriveEventsMapped<PublishedProfile>(repository, {
@@ -23,8 +24,10 @@ export const {
name: "profiles", name: "profiles",
store: profiles, store: profiles,
getKey: profile => profile.event.pubkey, getKey: profile => profile.event.pubkey,
load: (pubkey: string, request: Partial<SubscribeRequest> = {}) => load: async (pubkey: string, request: Partial<SubscribeRequest> = {}) => {
load({...request, filters: [{kinds: [PROFILE], authors: [pubkey]}]}), await loadRelaySelections(pubkey, request)
await load({...request, filters: [{kinds: [PROFILE], authors: [pubkey]}]})
},
}) })
export const profileSearch = derived(profiles, $profiles => export const profileSearch = derived(profiles, $profiles =>
+2 -1
View File
@@ -533,7 +533,8 @@ export const getFilterSelectionsForIndexedKinds = (state: FilterSelectionRuleSta
} }
export const getFilterSelectionsForAuthors = (state: FilterSelectionRuleState) => { export const getFilterSelectionsForAuthors = (state: FilterSelectionRuleState) => {
if (!state.filter.authors) return false // If we have a ton of authors, just use our indexers
if (!state.filter.authors || state.filter.authors.length > 30) return false
const id = getFilterId(state.filter) const id = getFilterId(state.filter)
const scenario = ctx.app.router.FromPubkeys(state.filter.authors!).update(assoc('value', id)) const scenario = ctx.app.router.FromPubkeys(state.filter.authors!).update(assoc('value', id))
+2 -2
View File
@@ -15,7 +15,7 @@ export const fetchZappers = async (lnurls: string[]) => {
// Use dufflepud if we it's set up to protect user privacy, otherwise fetch directly // Use dufflepud if we it's set up to protect user privacy, otherwise fetch directly
if (base) { if (base) {
const hexUrls = lnurls.map(lnurl => tryCatch(() => bech32ToHex(lnurl))).filter(identity) const hexUrls = lnurls.map(lnurl => tryCatch(() => bech32ToHex(lnurl))).filter(identity)
const res: any = await postJson(`${base}/zapper/info`, {lnurls: hexUrls}) const res: any = await tryCatch(async () => await postJson(`${base}/zapper/info`, {lnurls: hexUrls}))
for (const {lnurl, info} of res?.data || []) { for (const {lnurl, info} of res?.data || []) {
tryCatch(() => zappersByLnurl.set(hexToBech32("lnurl", lnurl), info)) tryCatch(() => zappersByLnurl.set(hexToBech32("lnurl", lnurl), info))
@@ -24,7 +24,7 @@ export const fetchZappers = async (lnurls: string[]) => {
const results = await Promise.all( const results = await Promise.all(
lnurls.map(async lnurl => { lnurls.map(async lnurl => {
const hexUrl = tryCatch(() => bech32ToHex(lnurl)) const hexUrl = tryCatch(() => bech32ToHex(lnurl))
const info = hexUrl ? await fetchJson(hexUrl) : undefined const info = hexUrl ? await tryCatch(async () => await fetchJson(hexUrl)) : undefined
return {lnurl, hexUrl, info} return {lnurl, hexUrl, info}
}) })
+1 -1
View File
@@ -189,7 +189,7 @@ export const optimizeSubscriptions = (subs: Subscription[]) => {
// This is sub-optimal, but because we're outsourcing filter/relay optimization // This is sub-optimal, but because we're outsourcing filter/relay optimization
// we can't make any assumptions about which caller subscriptions have completed // we can't make any assumptions about which caller subscriptions have completed
// at any given time. // at any given time.
if (subIds.size === group.length) { if (subIds.size === mergedSubs.length) {
for (const sub of group) { for (const sub of group) {
sub.emitter.emit(type, ...args) sub.emitter.emit(type, ...args)
} }