mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
Add relay fallback when healthy relays exhausted
This commit is contained in:
1 parent
ad6bd60f89
commit
05f092ff9b
1 file changed
+18
-1
+18
-1
@@ -3814,10 +3814,27 @@ export class NostrClient {
|
||||
: this.relays;
|
||||
|
||||
const healthyCandidates = this.getHealthyRelays(relaysToUse);
|
||||
let relayCandidates = healthyCandidates;
|
||||
if (!healthyCandidates.length && relaysToUse.length) {
|
||||
const sanitizedFallback = sanitizeRelayList(relaysToUse);
|
||||
const defaultFallback = sanitizeRelayList(Array.from(DEFAULT_RELAY_URLS));
|
||||
relayCandidates = sanitizedFallback.length
|
||||
? sanitizedFallback
|
||||
: defaultFallback.length
|
||||
? defaultFallback
|
||||
: sanitizeRelayList(Array.from(RELAY_URLS));
|
||||
devLogger.warn(
|
||||
"[fetchListIncrementally] Healthy relays exhausted; using fallback relay list for one-off fetch.",
|
||||
{
|
||||
requested: relaysToUse,
|
||||
fallback: relayCandidates,
|
||||
},
|
||||
);
|
||||
}
|
||||
const readPreferences = new Set(Array.isArray(this.readRelays) ? this.readRelays : []);
|
||||
|
||||
// Sort relays: prefer user's read relays first
|
||||
const sortedRelays = healthyCandidates.sort((a, b) => {
|
||||
const sortedRelays = relayCandidates.sort((a, b) => {
|
||||
const aPreferred = readPreferences.has(a);
|
||||
const bPreferred = readPreferences.has(b);
|
||||
if (aPreferred && !bPreferred) return -1;
|
||||
|
||||
Reference in new issue
Block a user