Speed up profile loading
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import {FOLLOWS, asDecryptedEvent, readList} from '@welshman/util'
|
||||
import {type TrustedEvent, type PublishedList} from '@welshman/util'
|
||||
import {type SubscribeRequest} from "@welshman/net"
|
||||
import {type SubscribeRequestWithHandlers} from "@welshman/net"
|
||||
import {deriveEventsMapped, withGetter} from '@welshman/store'
|
||||
import {repository, load} from './core'
|
||||
import {collection} from './collection'
|
||||
@@ -28,7 +28,7 @@ export const {
|
||||
name: "follows",
|
||||
store: follows,
|
||||
getKey: follows => follows.event.pubkey,
|
||||
load: async (pubkey: string, request: Partial<SubscribeRequest> = {}) => {
|
||||
load: async (pubkey: string, request: Partial<SubscribeRequestWithHandlers> = {}) => {
|
||||
await loadRelaySelections(pubkey, request)
|
||||
await load({...request, filters: [{kinds: [FOLLOWS], authors: [pubkey]}]})
|
||||
},
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {writable, derived} from 'svelte/store'
|
||||
import {withGetter} from '@welshman/store'
|
||||
import {type SubscribeRequest} from "@welshman/net"
|
||||
import {type SubscribeRequestWithHandlers} from "@welshman/net"
|
||||
import {ctx, tryCatch, fetchJson, uniq, batcher, postJson, last} from '@welshman/lib'
|
||||
import {collection} from './collection'
|
||||
import {deriveProfile} from './profiles'
|
||||
@@ -97,7 +97,7 @@ export const {
|
||||
}),
|
||||
})
|
||||
|
||||
export const deriveHandleForPubkey = (pubkey: string, request: Partial<SubscribeRequest> = {}) =>
|
||||
export const deriveHandleForPubkey = (pubkey: string, request: Partial<SubscribeRequestWithHandlers> = {}) =>
|
||||
derived(
|
||||
[handlesByNip05, deriveProfile(pubkey, request)],
|
||||
([$handlesByNip05, $profile]) => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {MUTES, asDecryptedEvent, readList} from '@welshman/util'
|
||||
import {type TrustedEvent, type PublishedList} from '@welshman/util'
|
||||
import {type SubscribeRequest} from "@welshman/net"
|
||||
import {type SubscribeRequestWithHandlers} from "@welshman/net"
|
||||
import {deriveEventsMapped, withGetter} from '@welshman/store'
|
||||
import {repository, load} from './core'
|
||||
import {collection} from './collection'
|
||||
@@ -28,7 +28,7 @@ export const {
|
||||
name: "mutes",
|
||||
store: mutes,
|
||||
getKey: mute => mute.event.pubkey,
|
||||
load: async (pubkey: string, request: Partial<SubscribeRequest> = {}) => {
|
||||
load: async (pubkey: string, request: Partial<SubscribeRequestWithHandlers> = {}) => {
|
||||
await loadRelaySelections(pubkey, request)
|
||||
await load({...request, filters: [{kinds: [MUTES], authors: [pubkey]}]})
|
||||
},
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {derived, readable} from 'svelte/store'
|
||||
import {readProfile, displayProfile, displayPubkey, PROFILE} from '@welshman/util'
|
||||
import {type SubscribeRequest} from "@welshman/net"
|
||||
import {type PublishedProfile} from "@welshman/util"
|
||||
import type {SubscribeRequestWithHandlers} from "@welshman/net"
|
||||
import type {PublishedProfile, TrustedEvent} from "@welshman/util"
|
||||
import {deriveEventsMapped, withGetter} from '@welshman/store'
|
||||
import {repository, load} from './core'
|
||||
import {createSearch} from './util'
|
||||
@@ -24,9 +24,24 @@ export const {
|
||||
name: "profiles",
|
||||
store: profiles,
|
||||
getKey: profile => profile.event.pubkey,
|
||||
load: async (pubkey: string, request: Partial<SubscribeRequest> = {}) => {
|
||||
await loadRelaySelections(pubkey, request)
|
||||
await load({...request, filters: [{kinds: [PROFILE], authors: [pubkey]}]})
|
||||
load: async (pubkey: string, request: Partial<SubscribeRequestWithHandlers> = {}) => {
|
||||
const filters = [{kinds: [PROFILE], authors: [pubkey]}]
|
||||
|
||||
// Attempt to load the user profile right away, regardless of whether we have relays,
|
||||
// since profiles are crucial to UX
|
||||
load({...request, filters})
|
||||
|
||||
// Load relay selections as quickly as possible, moving on to retrying profiles with
|
||||
// better selections the moment we have a result, even if it's outdated
|
||||
await new Promise<void>(resolve => {
|
||||
loadRelaySelections(pubkey, {
|
||||
onEvent: (event: TrustedEvent) => {
|
||||
resolve()
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
await load({...request, filters})
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {INBOX_RELAYS, RELAYS, getRelayTags, normalizeRelayUrl, type TrustedEvent} from '@welshman/util'
|
||||
import {type SubscribeRequest} from "@welshman/net"
|
||||
import {type SubscribeRequestWithHandlers} from "@welshman/net"
|
||||
import {deriveEvents, withGetter} from '@welshman/store'
|
||||
import {load, repository} from './core'
|
||||
import {collection} from './collection'
|
||||
@@ -28,7 +28,7 @@ export const {
|
||||
name: "relaySelections",
|
||||
store: relaySelections,
|
||||
getKey: relaySelections => relaySelections.pubkey,
|
||||
load: (pubkey: string, request: Partial<SubscribeRequest> = {}) =>
|
||||
load: (pubkey: string, request: Partial<SubscribeRequestWithHandlers> = {}) =>
|
||||
load({...request, filters: [{kinds: [RELAYS], authors: [pubkey]}]}),
|
||||
})
|
||||
|
||||
@@ -42,6 +42,6 @@ export const {
|
||||
name: "inboxRelaySelections",
|
||||
store: inboxRelaySelections,
|
||||
getKey: inboxRelaySelections => inboxRelaySelections.pubkey,
|
||||
load: (pubkey: string, request: Partial<SubscribeRequest> = {}) =>
|
||||
load: (pubkey: string, request: Partial<SubscribeRequestWithHandlers> = {}) =>
|
||||
load({...request, filters: [{kinds: [INBOX_RELAYS], authors: [pubkey]}]}),
|
||||
})
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {writable, derived} from 'svelte/store'
|
||||
import {withGetter} from '@welshman/store'
|
||||
import {type Zapper} from '@welshman/util'
|
||||
import {type SubscribeRequest} from "@welshman/net"
|
||||
import {type SubscribeRequestWithHandlers} from "@welshman/net"
|
||||
import {ctx, identity, fetchJson, uniq, bech32ToHex, hexToBech32, tryCatch, batcher, postJson} from '@welshman/lib'
|
||||
import {collection} from './collection'
|
||||
import {deriveProfile} from './profiles'
|
||||
@@ -15,10 +15,13 @@ 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 tryCatch(async () => await postJson(`${base}/zapper/info`, {lnurls: hexUrls}))
|
||||
|
||||
for (const {lnurl, info} of res?.data || []) {
|
||||
tryCatch(() => zappersByLnurl.set(hexToBech32("lnurl", lnurl), info))
|
||||
if (hexUrls.length > 0) {
|
||||
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))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const results = await Promise.all(
|
||||
@@ -68,7 +71,7 @@ export const {
|
||||
}),
|
||||
})
|
||||
|
||||
export const deriveZapperForPubkey = (pubkey: string, request: Partial<SubscribeRequest> = {}) =>
|
||||
export const deriveZapperForPubkey = (pubkey: string, request: Partial<SubscribeRequestWithHandlers> = {}) =>
|
||||
derived(
|
||||
[zappersByLnurl, deriveProfile(pubkey, request)],
|
||||
([$zappersByLnurl, $profile]) => {
|
||||
|
||||
Reference in New Issue
Block a user