mirror of
https://github.com/dergigi/boris.git
synced 2025-12-19 07:34:28 +01:00
perf(local-first): always follow up with remote for articles and titles
This commit is contained in:
@@ -103,7 +103,7 @@ export async function fetchArticleByNaddr(
|
||||
? pointer.relays
|
||||
: RELAYS
|
||||
const orderedRelays = prioritizeLocalRelays(baseRelays)
|
||||
const { local: localRelays } = partitionRelays(orderedRelays)
|
||||
const { local: localRelays, remote: remoteRelays } = partitionRelays(orderedRelays)
|
||||
|
||||
// Fetch the article event
|
||||
const filter = {
|
||||
@@ -112,7 +112,7 @@ export async function fetchArticleByNaddr(
|
||||
'#d': [pointer.identifier]
|
||||
}
|
||||
|
||||
// Local-first: try local relays quickly, then fallback to remote if no result
|
||||
// Local-first: try local relays quickly, then ALWAYS query remote to merge
|
||||
let events = [] as NostrEvent[]
|
||||
if (localRelays.length > 0) {
|
||||
try {
|
||||
@@ -131,11 +131,12 @@ export async function fetchArticleByNaddr(
|
||||
}
|
||||
}
|
||||
|
||||
if (events.length === 0) {
|
||||
// Fallback: query all relays, but still time-box
|
||||
events = await lastValueFrom(
|
||||
// Always query remote to ensure we have the latest from the wider network
|
||||
if (remoteRelays.length > 0) {
|
||||
try {
|
||||
const remoteEvents = await lastValueFrom(
|
||||
relayPool
|
||||
.req(orderedRelays, filter)
|
||||
.req(remoteRelays, filter)
|
||||
.pipe(
|
||||
onlyEvents(),
|
||||
take(1),
|
||||
@@ -143,6 +144,10 @@ export async function fetchArticleByNaddr(
|
||||
toArray()
|
||||
)
|
||||
)
|
||||
events = events.concat(remoteEvents)
|
||||
} catch {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
|
||||
if (events.length === 0) {
|
||||
|
||||
@@ -30,7 +30,7 @@ export async function fetchArticleTitle(
|
||||
? pointer.relays
|
||||
: RELAYS
|
||||
const orderedRelays = prioritizeLocalRelays(baseRelays)
|
||||
const { local: localRelays } = partitionRelays(orderedRelays)
|
||||
const { local: localRelays, remote: remoteRelays } = partitionRelays(orderedRelays)
|
||||
|
||||
// Fetch the article event
|
||||
const filter = {
|
||||
@@ -52,14 +52,14 @@ export async function fetchArticleTitle(
|
||||
events = []
|
||||
}
|
||||
}
|
||||
// Fallback to all relays if nothing from local quickly
|
||||
if (events.length === 0) {
|
||||
const fallbackEvents = await lastValueFrom(
|
||||
// Always follow up with remote relays to ensure we have latest network data
|
||||
if (remoteRelays.length > 0) {
|
||||
const remoteEvents = await lastValueFrom(
|
||||
relayPool
|
||||
.req(orderedRelays, filter)
|
||||
.req(remoteRelays, filter)
|
||||
.pipe(onlyEvents(), take(1), takeUntil(timer(5000)), toArray())
|
||||
)
|
||||
events = fallbackEvents as { created_at: number }[]
|
||||
events = events.concat(remoteEvents as unknown as { created_at: number }[])
|
||||
}
|
||||
|
||||
if (events.length === 0) {
|
||||
|
||||
Reference in New Issue
Block a user