Remove default throttle on event stores, add indexer relays to router
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
import {first, switcher, throttleWithValue, clamp, last, splitAt, identity, sortBy, uniq, shuffle, pushToMapKey} from '@welshman/lib'
|
||||
import {Tags, getFilterId, unionFilters, isShareableRelayUrl, isCommunityAddress, isGroupAddress, isContextAddress} from '@welshman/util'
|
||||
import {
|
||||
intersection, first, switcher, throttleWithValue, clamp, last, splitAt, identity, sortBy, uniq, shuffle,
|
||||
pushToMapKey,
|
||||
} from '@welshman/lib'
|
||||
import {
|
||||
Tags, getFilterId, unionFilters, isShareableRelayUrl, isCommunityAddress, isGroupAddress, isContextAddress,
|
||||
PROFILE, RELAYS, INBOX_RELAYS, FOLLOWS,
|
||||
} from '@welshman/util'
|
||||
import type {TrustedEvent, Filter} from '@welshman/util'
|
||||
import {NetworkContext, ConnectionStatus} from '@welshman/net'
|
||||
import {AppContext} from './core'
|
||||
@@ -7,6 +13,14 @@ import {pubkey} from './session'
|
||||
import {relaySelectionsByPubkey, getReadRelayUrls, getWriteRelayUrls, getRelayUrls} from './relaySelections'
|
||||
import {relays, relaysByUrl} from './relays'
|
||||
|
||||
export const INDEXED_KINDS = [PROFILE, RELAYS, INBOX_RELAYS, FOLLOWS]
|
||||
|
||||
export const INDEXER_RELAYS = [
|
||||
'wss://purplepag.es/',
|
||||
'wss://relay.damus.io/',
|
||||
'wss://relay.nostr.band/',
|
||||
]
|
||||
|
||||
export enum RelayMode {
|
||||
Read = "read",
|
||||
Write = "write",
|
||||
@@ -48,6 +62,12 @@ export type RouterOptions = {
|
||||
*/
|
||||
getFallbackRelays: () => string[]
|
||||
|
||||
/**
|
||||
* Retrieves relays that index profiles and relay selections.
|
||||
* @returns An array of relay URLs as strings.
|
||||
*/
|
||||
getIndexerRelays?: () => string[]
|
||||
|
||||
/**
|
||||
* Retrieves relays likely to support NIP-50 search.
|
||||
* @returns An array of relay URLs as strings.
|
||||
@@ -419,6 +439,8 @@ export const getPubkeyRelays = (pubkey: string, mode?: string) => {
|
||||
}
|
||||
}
|
||||
|
||||
export const getIndexerRelays = () => INDEXER_RELAYS
|
||||
|
||||
export const getFallbackRelays = throttleWithValue(300, () =>
|
||||
relays.get().filter(r => getRelayQuality(r.url) >= 0.5).map(r => r.url)
|
||||
)
|
||||
@@ -430,6 +452,7 @@ export const getSearchRelays = throttleWithValue(300, () =>
|
||||
export const makeRouter = (options: Partial<RouterOptions> = {}) =>
|
||||
new Router({
|
||||
getPubkeyRelays,
|
||||
getIndexerRelays,
|
||||
getFallbackRelays,
|
||||
getSearchRelays,
|
||||
getRelayQuality,
|
||||
@@ -463,6 +486,15 @@ export const getFilterSelectionsForSearch = (filter: Filter) => {
|
||||
return [makeFilterSelection(id, filter, scenario)]
|
||||
}
|
||||
|
||||
export const getFilterSelectionsForIndexedKinds = (filter: Filter) => {
|
||||
const kinds = intersection(INDEXED_KINDS, filter.kinds!)
|
||||
const id = getFilterId({...filter, kinds})
|
||||
const relays = AppContext.router.options.getIndexerRelays?.() || []
|
||||
const scenario = AppContext.router.product([id], relays)
|
||||
|
||||
return [makeFilterSelection(id, filter, scenario)]
|
||||
}
|
||||
|
||||
export const getFilterSelectionsForContext = (filter: Filter) => {
|
||||
const filterSelections = []
|
||||
const contexts = filter["#a"].filter(isContextAddress)
|
||||
@@ -536,6 +568,10 @@ export const getFilterSelections = (filters: Filter[]): RelayFilters[] => {
|
||||
addSelections(getFilterSelectionsForSearch(filter))
|
||||
}
|
||||
|
||||
if (filter.kinds?.some(k => INDEXED_KINDS.includes(k))) {
|
||||
addSelections(getFilterSelectionsForIndexedKinds(filter))
|
||||
}
|
||||
|
||||
if (filter["#a"]?.some(isContextAddress)) {
|
||||
addSelections(getFilterSelectionsForContext(filter))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user