Fix load bypassing freshness

This commit is contained in:
Jon Staab
2024-09-02 15:57:40 -07:00
parent 9a5a423b3e
commit b910569fc0
8 changed files with 80 additions and 61 deletions
+13 -14
View File
@@ -2,17 +2,19 @@ import {derived} from 'svelte/store'
import {readProfile, displayProfile, displayPubkey, PROFILE} from '@welshman/util'
import {type SubscribeRequest} from "@welshman/net"
import {type PublishedProfile} from "@welshman/util"
import {deriveEventsMapped} from '@welshman/store'
import {deriveEventsMapped, withGetter} from '@welshman/store'
import {repository, load} from './core'
import {createSearch} from './util'
import {collection} from './collection'
import {getWriteRelayUrls, loadRelaySelections} from './relaySelections'
import {getHintsForPubkey} from './relaySelections'
export const profiles = deriveEventsMapped<PublishedProfile>(repository, {
filters: [{kinds: [PROFILE]}],
eventToItem: readProfile,
itemToEvent: item => item.event,
})
export const profiles = withGetter(
deriveEventsMapped<PublishedProfile>(repository, {
filters: [{kinds: [PROFILE]}],
eventToItem: readProfile,
itemToEvent: item => item.event,
})
)
export const {
indexStore: profilesByPubkey,
@@ -22,15 +24,12 @@ export const {
name: "profiles",
store: profiles,
getKey: profile => profile.event.pubkey,
load: async (pubkey: string, hints = [], request: Partial<SubscribeRequest> = {}) => {
const relays = getWriteRelayUrls(await loadRelaySelections(pubkey, hints))
return load({
load: async (pubkey: string, request: Partial<SubscribeRequest> = {}) =>
load({
...request,
relays: [...relays, ...hints],
filters: [{kinds: [PROFILE], authors: [pubkey]}],
})
},
relays: await getHintsForPubkey(pubkey, request.relays || []),
}),
})
export const profileSearch = derived(profiles, $profiles =>