client: use the same pool as the firehose
This commit is contained in:
parent
17c75e6761
commit
5f82f4f11b
|
@ -1,32 +1,9 @@
|
|||
import { Conf } from '@/config.ts';
|
||||
import { type Event, type Filter, matchFilters, RelayPool, TTLCache } from '@/deps.ts';
|
||||
import { type Event, type Filter, matchFilters } from '@/deps.ts';
|
||||
import * as pipeline from '@/pipeline.ts';
|
||||
import { Time } from '@/utils.ts';
|
||||
import { allRelays, pool } from '@/pool.ts';
|
||||
|
||||
import type { GetFiltersOpts } from '@/filter.ts';
|
||||
|
||||
type Pool = InstanceType<typeof RelayPool>;
|
||||
|
||||
/** HACK: Websockets in Deno are finnicky... get a new pool every 30 minutes. */
|
||||
const poolCache = new TTLCache<0, Pool>({
|
||||
ttl: Time.minutes(30),
|
||||
max: 2,
|
||||
dispose: (pool) => {
|
||||
console.log('Closing pool.');
|
||||
pool.close();
|
||||
},
|
||||
});
|
||||
|
||||
function getPool(): Pool {
|
||||
const cached = poolCache.get(0);
|
||||
if (cached !== undefined) return cached;
|
||||
|
||||
console.log('Creating new pool.');
|
||||
const pool = new RelayPool(Conf.poolRelays);
|
||||
poolCache.set(0, pool);
|
||||
return pool;
|
||||
}
|
||||
|
||||
/** Get events from a NIP-01 filter. */
|
||||
function getFilters<K extends number>(filters: Filter<K>[], opts: GetFiltersOpts = {}): Promise<Event<K>[]> {
|
||||
if (!filters.length) return Promise.resolve([]);
|
||||
|
@ -34,9 +11,9 @@ function getFilters<K extends number>(filters: Filter<K>[], opts: GetFiltersOpts
|
|||
let tid: number;
|
||||
const results: Event[] = [];
|
||||
|
||||
const unsub = getPool().subscribe(
|
||||
const unsub = pool.subscribe(
|
||||
filters,
|
||||
Conf.poolRelays,
|
||||
allRelays,
|
||||
(event: Event | null) => {
|
||||
if (event && matchFilters(filters, event)) {
|
||||
pipeline.handleEvent(event).catch(() => {});
|
||||
|
|
|
@ -58,14 +58,6 @@ const Conf = {
|
|||
get adminEmail() {
|
||||
return Deno.env.get('ADMIN_EMAIL') || 'webmaster@localhost';
|
||||
},
|
||||
/** @deprecated Use relays from the database instead. */
|
||||
get poolRelays() {
|
||||
return (Deno.env.get('RELAY_POOL') || '').split(',').filter(Boolean);
|
||||
},
|
||||
/** @deprecated Publish only to the local relay unless users are mentioned, then try to also send to the relay of those users. Deletions should also be fanned out. */
|
||||
get publishRelays() {
|
||||
return ['wss://relay.mostr.pub'];
|
||||
},
|
||||
/** Domain of the Ditto server as a `URL` object, for easily grabbing the `hostname`, etc. */
|
||||
get url() {
|
||||
return new URL(Conf.localDomain);
|
||||
|
|
Loading…
Reference in New Issue