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 {collection} from './collection'
import {ensurePlaintext} from './plaintext'
import {loadRelaySelections} from './relaySelections'
export const follows = withGetter(
deriveEventsMapped<PublishedList>(repository, {
@@ -27,6 +28,8 @@ export const {
name: "follows",
store: follows,
getKey: follows => follows.event.pubkey,
load: (pubkey: string, request: Partial<SubscribeRequest> = {}) =>
load({...request, filters: [{kinds: [FOLLOWS], authors: [pubkey]}]}),
load: async (pubkey: string, request: Partial<SubscribeRequest> = {}) => {
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 {withGetter} from '@welshman/store'
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 {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
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 || []) {
handlesByNip05.set(nip05, info)
}
} else {
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) {
+5 -2
View File
@@ -5,6 +5,7 @@ import {deriveEventsMapped, withGetter} from '@welshman/store'
import {repository, load} from './core'
import {collection} from './collection'
import {ensurePlaintext} from './plaintext'
import {loadRelaySelections} from './relaySelections'
export const mutes = withGetter(
deriveEventsMapped<PublishedList>(repository, {
@@ -27,6 +28,8 @@ export const {
name: "mutes",
store: mutes,
getKey: mute => mute.event.pubkey,
load: (pubkey: string, request: Partial<SubscribeRequest> = {}) =>
load({...request, filters: [{kinds: [MUTES], authors: [pubkey]}]}),
load: async (pubkey: string, request: Partial<SubscribeRequest> = {}) => {
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 {createSearch} from './util'
import {collection} from './collection'
import {loadRelaySelections} from './relaySelections'
export const profiles = withGetter(
deriveEventsMapped<PublishedProfile>(repository, {
@@ -23,8 +24,10 @@ export const {
name: "profiles",
store: profiles,
getKey: profile => profile.event.pubkey,
load: (pubkey: string, request: Partial<SubscribeRequest> = {}) =>
load({...request, filters: [{kinds: [PROFILE], authors: [pubkey]}]}),
load: async (pubkey: string, request: Partial<SubscribeRequest> = {}) => {
await loadRelaySelections(pubkey, request)
await load({...request, filters: [{kinds: [PROFILE], authors: [pubkey]}]})
},
})
export const profileSearch = derived(profiles, $profiles =>
+2 -1
View File
@@ -533,7 +533,8 @@ export const getFilterSelectionsForIndexedKinds = (state: FilterSelectionRuleSta
}
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 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
if (base) {
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 || []) {
tryCatch(() => zappersByLnurl.set(hexToBech32("lnurl", lnurl), info))
@@ -24,7 +24,7 @@ export const fetchZappers = async (lnurls: string[]) => {
const results = await Promise.all(
lnurls.map(async 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}
})