Optimize feeds a bit more, push local relay url up a layer to avoid opting in when we don't want it
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import {partition} from "@welshman/lib"
|
||||
import {defaultOptimizeSubscriptions, getDefaultNetContext as originalGetDefaultNetContext} from "@welshman/net"
|
||||
import type {Subscription, RelaysAndFilters, NetContext} from "@welshman/net"
|
||||
import {WRAP, isEphemeralKind, isDVMKind, unionFilters} from "@welshman/util"
|
||||
import {WRAP, LOCAL_RELAY_URL, isEphemeralKind, isDVMKind, unionFilters} from "@welshman/util"
|
||||
import type {TrustedEvent, StampedEvent} from "@welshman/util"
|
||||
import {tracker, repository} from './core'
|
||||
import {makeRouter, getFilterSelections} from './router'
|
||||
@@ -38,8 +38,10 @@ export const getDefaultNetContext = (overrides: Partial<NetContext> = {}) => ({
|
||||
const filters = unionFilters(withoutRelays.flatMap(sub => sub.request.filters))
|
||||
const selections: RelaysAndFilters[] = defaultOptimizeSubscriptions(withRelays)
|
||||
|
||||
selections.push({relays: [LOCAL_RELAY_URL], filters})
|
||||
|
||||
if (filters.length > 0) {
|
||||
for (const selection of getFilterSelections(filters)) {
|
||||
for (const selection of getFilterSelections(filters)) {
|
||||
selections.push(selection)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,10 +25,10 @@ import {
|
||||
RELAYS,
|
||||
INBOX_RELAYS,
|
||||
FOLLOWS,
|
||||
LOCAL_RELAY_URL,
|
||||
WRAP,
|
||||
getAncestorTags,
|
||||
getPubkeyTagValues
|
||||
getPubkeyTagValues,
|
||||
normalizeRelayUrl,
|
||||
} from "@welshman/util"
|
||||
import type {TrustedEvent, Filter} from "@welshman/util"
|
||||
import type {RelaysAndFilters} from "@welshman/net"
|
||||
@@ -103,7 +103,8 @@ export type Selection = {
|
||||
relays: string[],
|
||||
}
|
||||
|
||||
const makeSelection = (relays: string[], weight = 1): Selection => ({relays, weight})
|
||||
const makeSelection = (relays: string[], weight = 1): Selection =>
|
||||
({relays: relays.map(normalizeRelayUrl), weight})
|
||||
|
||||
// Fallback policies
|
||||
|
||||
@@ -427,7 +428,7 @@ export const defaultFilterSelectionRules = [
|
||||
|
||||
export const getFilterSelections = (
|
||||
filters: Filter[],
|
||||
rules: FilterSelectionRule[] = defaultFilterSelectionRules
|
||||
rules: FilterSelectionRule[] = defaultFilterSelectionRules
|
||||
): RelaysAndFilters[] => {
|
||||
const filtersById = new Map<string, Filter>()
|
||||
const scenariosById = new Map<string, RouterScenario[]>()
|
||||
@@ -445,9 +446,8 @@ export const getFilterSelections = (
|
||||
|
||||
for (const [id, filter] of filtersById.entries()) {
|
||||
const scenario = ctx.app.router.merge(scenariosById.get(id) || [])
|
||||
const relays = scenario.getUrls().concat(LOCAL_RELAY_URL)
|
||||
|
||||
result.push({filters: [filter], relays})
|
||||
result.push({filters: [filter], relays: scenario.getUrls()})
|
||||
}
|
||||
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user