Use only "active" relays in the pool

This commit is contained in:
Alex Gleason 2023-08-16 08:28:52 -05:00
parent a0769d7c92
commit 882a3fe203
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 6 additions and 5 deletions

View File

@ -17,14 +17,15 @@ function addRelays(relays: `wss://${string}`[]) {
.execute();
}
/** Get a list of all known good relays. */
async function getAllRelays(): Promise<string[]> {
/** Get a list of all known active relay URLs. */
async function getActiveRelays(): Promise<string[]> {
const rows = await db
.selectFrom('relays')
.select('relays.url')
.where('relays.active', '=', true)
.execute();
return rows.map((row) => row.url);
}
export { addRelays, getAllRelays };
export { addRelays, getActiveRelays };

View File

@ -1,5 +1,5 @@
import { insertEvent, isLocallyFollowed } from '@/db/events.ts';
import { addRelays, getAllRelays } from '@/db/relays.ts';
import { addRelays, getActiveRelays } from '@/db/relays.ts';
import { findUser } from '@/db/users.ts';
import { RelayPool } from '@/deps.ts';
import { trends } from '@/trends.ts';
@ -7,7 +7,7 @@ import { isRelay, nostrDate, nostrNow } from '@/utils.ts';
import type { SignedEvent } from '@/event.ts';
const relays = await getAllRelays();
const relays = await getActiveRelays();
const pool = new RelayPool(relays);
// This file watches events on all known relays and performs