From 107fe76fdff72ab07aaa5b20ce1648e66edc8ac6 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sun, 17 Dec 2023 14:55:59 -0600 Subject: [PATCH] Move the RelayPool to a worker thread --- src/deps.ts | 2 +- src/pool.ts | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/deps.ts b/src/deps.ts index a6b893cd..85cbd7b2 100644 --- a/src/deps.ts +++ b/src/deps.ts @@ -9,7 +9,7 @@ export { } from 'https://deno.land/x/hono@v3.10.1/mod.ts'; export { cors, logger, serveStatic } from 'https://deno.land/x/hono@v3.10.1/middleware.ts'; export { z } from 'https://deno.land/x/zod@v3.21.4/mod.ts'; -export { Author, RelayPool } from 'https://dev.jspm.io/nostr-relaypool@0.6.30'; +export { Author, RelayPoolWorker } from 'https://dev.jspm.io/nostr-relaypool@0.6.30'; export { type Event, type EventTemplate, diff --git a/src/pool.ts b/src/pool.ts index 07ac6b62..da186160 100644 --- a/src/pool.ts +++ b/src/pool.ts @@ -1,11 +1,14 @@ import { getActiveRelays } from '@/db/relays.ts'; -import { type Event, RelayPool } from '@/deps.ts'; +import { type Event, RelayPoolWorker } from '@/deps.ts'; const activeRelays = await getActiveRelays(); console.log(`pool: connecting to ${activeRelays.length} relays.`); -const pool = new RelayPool(activeRelays, { +const worker = new Worker('https://unpkg.com/nostr-relaypool@0.6.30/lib/nostr-relaypool.worker.js', { type: 'module' }); + +// @ts-ignore Wrong types. +const pool = new RelayPoolWorker(worker, activeRelays, { // The pipeline verifies events. skipVerification: true, // The logging feature overwhelms the CPU and creates too many logs.