mirror of
https://github.com/dergigi/boris.git
synced 2025-12-24 01:54:19 +01:00
fix: publish only to connected relays to avoid long timeouts
- Only publish to currently connected relays instead of all configured relays - This prevents waiting for disconnected/offline relays to timeout - Improves performance significantly in flight mode - Handle case when no relays are connected
This commit is contained in:
@@ -124,21 +124,29 @@ export async function createHighlight(
|
|||||||
isSyncing: false
|
isSyncing: false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Publish to all relays and get individual responses
|
// Get only connected relays to avoid long timeouts
|
||||||
const allRelays = RELAYS
|
const connectedRelays = Array.from(relayPool.relays.values())
|
||||||
|
.filter(relay => relay.connected)
|
||||||
|
.map(relay => relay.url)
|
||||||
|
|
||||||
let publishResponses: { ok: boolean; message?: string; from: string }[] = []
|
let publishResponses: { ok: boolean; message?: string; from: string }[] = []
|
||||||
let isLocalOnly = false
|
let isLocalOnly = false
|
||||||
|
|
||||||
console.log('🚀 [HIGHLIGHT-PUBLISH] Starting highlight publication process', {
|
console.log('🚀 [HIGHLIGHT-PUBLISH] Starting highlight publication process', {
|
||||||
eventId: signedEvent.id,
|
eventId: signedEvent.id,
|
||||||
allRelays,
|
connectedRelays,
|
||||||
relayCount: allRelays.length
|
connectedRelayCount: connectedRelays.length
|
||||||
})
|
})
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Publish to all relays and wait for responses
|
// Publish only to connected relays to avoid long timeouts
|
||||||
console.log('📡 [HIGHLIGHT-PUBLISH] Publishing to all relays...')
|
if (connectedRelays.length === 0) {
|
||||||
publishResponses = await relayPool.publish(allRelays, signedEvent)
|
console.log('⚠️ [HIGHLIGHT-PUBLISH] No connected relays, marking as local-only')
|
||||||
|
isLocalOnly = true
|
||||||
|
} else {
|
||||||
|
console.log('📡 [HIGHLIGHT-PUBLISH] Publishing to connected relays...')
|
||||||
|
publishResponses = await relayPool.publish(connectedRelays, signedEvent)
|
||||||
|
}
|
||||||
|
|
||||||
console.log('📨 [HIGHLIGHT-PUBLISH] Received responses from relays:', publishResponses)
|
console.log('📨 [HIGHLIGHT-PUBLISH] Received responses from relays:', publishResponses)
|
||||||
|
|
||||||
@@ -158,7 +166,7 @@ export async function createHighlight(
|
|||||||
isLocalOnly = successfulLocalRelays.length > 0 && successfulRemoteRelays.length === 0
|
isLocalOnly = successfulLocalRelays.length > 0 && successfulRemoteRelays.length === 0
|
||||||
|
|
||||||
console.log('✅ [HIGHLIGHT-PUBLISH] Publishing analysis:', {
|
console.log('✅ [HIGHLIGHT-PUBLISH] Publishing analysis:', {
|
||||||
totalRelays: allRelays.length,
|
connectedRelays: connectedRelays.length,
|
||||||
successfulRelays: successfulRelays.length,
|
successfulRelays: successfulRelays.length,
|
||||||
failedRelays: failedRelays.length,
|
failedRelays: failedRelays.length,
|
||||||
successfulLocalRelays,
|
successfulLocalRelays,
|
||||||
@@ -172,11 +180,16 @@ export async function createHighlight(
|
|||||||
: 'No relays accepted the event'
|
: 'No relays accepted the event'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Handle case when no relays were connected
|
||||||
|
const successfulRelaysList = publishResponses.length > 0
|
||||||
|
? publishResponses
|
||||||
|
.filter(response => response.ok)
|
||||||
|
.map(response => response.from)
|
||||||
|
: []
|
||||||
|
|
||||||
// Update the event with the actual properties
|
// Update the event with the actual properties
|
||||||
;(signedEvent as any).__highlightProps = {
|
;(signedEvent as any).__highlightProps = {
|
||||||
publishedRelays: publishResponses
|
publishedRelays: successfulRelaysList,
|
||||||
.filter(response => response.ok)
|
|
||||||
.map(response => response.from),
|
|
||||||
isLocalOnly,
|
isLocalOnly,
|
||||||
isSyncing: false
|
isSyncing: false
|
||||||
}
|
}
|
||||||
@@ -217,9 +230,13 @@ export async function createHighlight(
|
|||||||
const highlight = eventToHighlight(signedEvent)
|
const highlight = eventToHighlight(signedEvent)
|
||||||
|
|
||||||
// Manually set the properties since __highlightProps might not be working
|
// Manually set the properties since __highlightProps might not be working
|
||||||
highlight.publishedRelays = publishResponses
|
const finalPublishedRelays = publishResponses.length > 0
|
||||||
.filter(response => response.ok)
|
? publishResponses
|
||||||
.map(response => response.from)
|
.filter(response => response.ok)
|
||||||
|
.map(response => response.from)
|
||||||
|
: []
|
||||||
|
|
||||||
|
highlight.publishedRelays = finalPublishedRelays
|
||||||
highlight.isLocalOnly = isLocalOnly
|
highlight.isLocalOnly = isLocalOnly
|
||||||
highlight.isSyncing = false
|
highlight.isSyncing = false
|
||||||
|
|
||||||
@@ -227,7 +244,8 @@ export async function createHighlight(
|
|||||||
eventId: signedEvent.id,
|
eventId: signedEvent.id,
|
||||||
publishedRelays: highlight.publishedRelays,
|
publishedRelays: highlight.publishedRelays,
|
||||||
isLocalOnly: highlight.isLocalOnly,
|
isLocalOnly: highlight.isLocalOnly,
|
||||||
isSyncing: highlight.isSyncing
|
isSyncing: highlight.isSyncing,
|
||||||
|
relayCount: highlight.publishedRelays.length
|
||||||
})
|
})
|
||||||
|
|
||||||
return highlight
|
return highlight
|
||||||
|
|||||||
Reference in New Issue
Block a user