diff --git a/src/controllers/MetadataController.ts b/src/controllers/MetadataController.ts index d3bd506..8053874 100644 --- a/src/controllers/MetadataController.ts +++ b/src/controllers/MetadataController.ts @@ -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)) { // If older than one week, find the metadata from relays in background diff --git a/src/controllers/RelayController.ts b/src/controllers/RelayController.ts index 860a3d4..40945ad 100644 --- a/src/controllers/RelayController.ts +++ b/src/controllers/RelayController.ts @@ -96,8 +96,12 @@ export class RelayController { relayUrls: string[] = [] ): Promise => { 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 => { 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 diff --git a/src/utils/relays.ts b/src/utils/relays.ts index 6c4b4e9..c38767c 100644 --- a/src/utils/relays.ts +++ b/src/utils/relays.ts @@ -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) - }) + ) getRelayInfo(Object.keys(relaysMap))