perf(relays): local-first queries with short timeouts; fallback to remote if needed

This commit is contained in:
Gigi
2025-10-12 22:06:49 +02:00
parent 86de98e644
commit 5513fc9850
6 changed files with 255 additions and 66 deletions

View File

@@ -63,3 +63,34 @@ export const hasRemoteRelay = (relayUrls: string[]): boolean => {
return relayUrls.some(url => !isLocalRelay(url))
}
/**
* Splits relay URLs into local and remote groups
*/
export const partitionRelays = (
relayUrls: string[]
): { local: string[]; remote: string[] } => {
const local: string[] = []
const remote: string[] = []
for (const url of relayUrls) {
if (isLocalRelay(url)) local.push(url)
else remote.push(url)
}
return { local, remote }
}
/**
* Returns relays ordered with local first while keeping uniqueness
*/
export const prioritizeLocalRelays = (relayUrls: string[]): string[] => {
const { local, remote } = partitionRelays(relayUrls)
const seen = new Set<string>()
const out: string[] = []
for (const url of [...local, ...remote]) {
if (!seen.has(url)) {
seen.add(url)
out.push(url)
}
}
return out
}