mirror of
https://github.com/dergigi/boris.git
synced 2026-01-22 16:24:30 +01:00
perf(relays): local-first queries with short timeouts; fallback to remote if needed
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user