mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
feat(storages): remove PoolStore, use NPool
This commit is contained in:
parent
e01e0049e3
commit
bccf33f80a
1 changed files with 19 additions and 20 deletions
|
|
@ -1,18 +1,17 @@
|
|||
// deno-lint-ignore-file require-await
|
||||
import { RelayPoolWorker } from 'nostr-relaypool';
|
||||
|
||||
import { Conf } from '@/config.ts';
|
||||
import { DittoDB } from '@/db/DittoDB.ts';
|
||||
import { AdminStore } from '@/storages/AdminStore.ts';
|
||||
import { EventsDB } from '@/storages/EventsDB.ts';
|
||||
import { PoolStore } from '@/storages/pool-store.ts';
|
||||
import { SearchStore } from '@/storages/search-store.ts';
|
||||
import { InternalRelay } from '@/storages/InternalRelay.ts';
|
||||
import { NPool, NRelay1 } from '@nostrify/nostrify';
|
||||
import { getRelays } from '@/utils/outbox.ts';
|
||||
|
||||
export class Storages {
|
||||
private static _db: Promise<EventsDB> | undefined;
|
||||
private static _admin: Promise<AdminStore> | undefined;
|
||||
private static _client: Promise<PoolStore> | undefined;
|
||||
private static _client: Promise<NPool> | undefined;
|
||||
private static _pubsub: Promise<InternalRelay> | undefined;
|
||||
private static _search: Promise<SearchStore> | undefined;
|
||||
|
||||
|
|
@ -44,7 +43,7 @@ export class Storages {
|
|||
}
|
||||
|
||||
/** Relay pool storage. */
|
||||
public static async client(): Promise<PoolStore> {
|
||||
public static async client(): Promise<NPool> {
|
||||
if (!this._client) {
|
||||
this._client = (async () => {
|
||||
const db = await this.db();
|
||||
|
|
@ -64,22 +63,22 @@ export class Storages {
|
|||
|
||||
console.log(`pool: connecting to ${activeRelays.length} relays.`);
|
||||
|
||||
const worker = new Worker('https://unpkg.com/nostr-relaypool2@0.6.34/lib/nostr-relaypool.worker.js', {
|
||||
type: 'module',
|
||||
});
|
||||
return new NPool({
|
||||
open(url) {
|
||||
return new NRelay1(url);
|
||||
},
|
||||
reqRouter: async (filters) => {
|
||||
return new Map(activeRelays.map((relay) => {
|
||||
return [relay, filters];
|
||||
}));
|
||||
},
|
||||
eventRouter: async (event) => {
|
||||
const relaySet = await getRelays(await Storages.db(), event.pubkey);
|
||||
relaySet.delete(Conf.relay);
|
||||
|
||||
// @ts-ignore Wrong types.
|
||||
const pool = new RelayPoolWorker(worker, activeRelays, {
|
||||
autoReconnect: true,
|
||||
// The pipeline verifies events.
|
||||
skipVerification: true,
|
||||
// The logging feature overwhelms the CPU and creates too many logs.
|
||||
logErrorsAndNotices: false,
|
||||
});
|
||||
|
||||
return new PoolStore({
|
||||
pool,
|
||||
relays: activeRelays,
|
||||
const relays = [...relaySet].slice(0, 4);
|
||||
return relays;
|
||||
},
|
||||
});
|
||||
})();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue