fix: manage pending relay connection requests #159

Merged
eugene merged 6 commits from reduce-relay-connection-attempts into staging 2024-08-21 08:06:39 +00:00
3 changed files with 19 additions and 11 deletions
Showing only changes of commit 4a553c047c - Show all commits

View File

@ -116,7 +116,7 @@ export class MetadataController extends EventEmitter {
// If cached metadata is found, check its validity
if (cachedMetadataEvent) {
// Check if the cached metadata is older than one week
// Check if the cached metadata is older than one day
if (isOlderThanOneDay(cachedMetadataEvent.cachedAt)) {
s marked this conversation as resolved
Review

There is a discrepancy between the function name and the comments around it. Should it be older than one week or one day?

There is a discrepancy between the function name and the comments around it. Should it be older than one week or one day?
Review

fixed, Updated comment

fixed, Updated comment
// If older than one week, find the metadata from relays in background

View File

@ -96,8 +96,12 @@ export class RelayController {
relayUrls: string[] = []
): Promise<Event[]> => {
if (!relayUrls.includes(SIGIT_RELAY)) {
// Add app relay to relays array if not exists already
relayUrls.push(SIGIT_RELAY)
/**
* NOTE: To avoid side-effects on external relayUrls array passed as argument
* re-assigned relayUrls with added sigit relay instead of just appending to same array
*/
relayUrls = [...relayUrls, SIGIT_RELAY] // Add app relay to relays array if not exists already
}
// connect to all specified relays
@ -216,8 +220,11 @@ export class RelayController {
eventHandler: (event: Event) => void
) => {
if (!relayUrls.includes(SIGIT_RELAY)) {
// Add app relay to relays array if not exists already
relayUrls.push(SIGIT_RELAY)
/**
* NOTE: To avoid side-effects on external relayUrls array passed as argument
* re-assigned relayUrls with added sigit relay instead of just appending to same array
*/
relayUrls = [...relayUrls, SIGIT_RELAY] // Add app relay to relays array if not exists already
}
// connect to all specified relays
@ -277,8 +284,11 @@ export class RelayController {
relayUrls: string[] = []
): Promise<string[]> => {
if (!relayUrls.includes(SIGIT_RELAY)) {
// Add app relay to relays array if not exists already
relayUrls.push(SIGIT_RELAY)
/**
* NOTE: To avoid side-effects on external relayUrls array passed as argument
* re-assigned relayUrls with added sigit relay instead of just appending to same array
*/
relayUrls = [...relayUrls, SIGIT_RELAY] // Add app relay to relays array if not exists already
}
// connect to all specified relays

View File

@ -130,7 +130,6 @@ const getRelayMap = async (
authors: [npub]
}
console.count('getRelayMap')
const event = await relayController
.fetchEvent(eventFilter, DEFAULT_LOOK_UP_RELAY_LIST)
.catch((err) => {
@ -155,10 +154,9 @@ const getRelayMap = async (
}
})
Object.keys(relaysMap).forEach((relayUrl) => {
console.log('being called from getRelayMap')
Object.keys(relaysMap).forEach((relayUrl) =>
relayController.connectRelay(relayUrl)
})
)
s marked this conversation as resolved Outdated

Should this console log be removed?

Should this console log be removed?
Outdated
Review

removed

removed
getRelayInfo(Object.keys(relaysMap))