2024-04-19 21:39:35 +00:00
|
|
|
import { NCache } from '@nostrify/nostrify';
|
2024-01-04 06:07:45 +00:00
|
|
|
import { Conf } from '@/config.ts';
|
2024-01-04 03:55:53 +00:00
|
|
|
import { db } from '@/db.ts';
|
2024-01-07 21:15:20 +00:00
|
|
|
import * as pipeline from '@/pipeline.ts';
|
|
|
|
import { activeRelays, pool } from '@/pool.ts';
|
2024-01-04 03:55:53 +00:00
|
|
|
import { EventsDB } from '@/storages/events-db.ts';
|
2024-01-04 06:52:55 +00:00
|
|
|
import { Optimizer } from '@/storages/optimizer.ts';
|
2024-01-07 21:15:20 +00:00
|
|
|
import { PoolStore } from '@/storages/pool-store.ts';
|
2024-01-07 20:54:33 +00:00
|
|
|
import { Reqmeister } from '@/storages/reqmeister.ts';
|
2024-01-04 06:07:45 +00:00
|
|
|
import { SearchStore } from '@/storages/search-store.ts';
|
2024-04-25 23:28:19 +00:00
|
|
|
import { InternalRelay } from '@/storages/InternalRelay.ts';
|
2024-01-07 20:54:33 +00:00
|
|
|
import { Time } from '@/utils/time.ts';
|
2024-01-04 03:55:53 +00:00
|
|
|
|
2024-01-07 21:15:20 +00:00
|
|
|
/** Relay pool storage. */
|
|
|
|
const client = new PoolStore({
|
|
|
|
pool,
|
|
|
|
relays: activeRelays,
|
|
|
|
publisher: pipeline,
|
|
|
|
});
|
|
|
|
|
2024-01-04 03:55:53 +00:00
|
|
|
/** SQLite database to store events this Ditto server cares about. */
|
|
|
|
const eventsDB = new EventsDB(db);
|
|
|
|
|
|
|
|
/** In-memory data store for cached events. */
|
2024-01-23 23:50:33 +00:00
|
|
|
const cache = new NCache({ max: 3000 });
|
2024-01-04 03:55:53 +00:00
|
|
|
|
2024-01-07 20:54:33 +00:00
|
|
|
/** Batches requests for single events. */
|
|
|
|
const reqmeister = new Reqmeister({
|
2024-01-07 20:58:17 +00:00
|
|
|
client,
|
2024-01-07 20:54:33 +00:00
|
|
|
delay: Time.seconds(1),
|
|
|
|
timeout: Time.seconds(1),
|
|
|
|
});
|
|
|
|
|
2024-01-04 06:52:55 +00:00
|
|
|
/** Main Ditto storage adapter */
|
|
|
|
const optimizer = new Optimizer({
|
|
|
|
db: eventsDB,
|
2024-01-23 23:50:33 +00:00
|
|
|
cache,
|
2024-01-04 06:52:55 +00:00
|
|
|
client: reqmeister,
|
|
|
|
});
|
|
|
|
|
2024-01-04 06:07:45 +00:00
|
|
|
/** Storage to use for remote search. */
|
|
|
|
const searchStore = new SearchStore({
|
|
|
|
relay: Conf.searchRelay,
|
2024-01-04 06:52:55 +00:00
|
|
|
fallback: optimizer,
|
2024-01-04 06:07:45 +00:00
|
|
|
});
|
|
|
|
|
2024-04-25 23:28:19 +00:00
|
|
|
export class Storages {
|
2024-04-25 23:31:16 +00:00
|
|
|
private static _pubsub: InternalRelay | undefined;
|
2024-04-25 23:28:19 +00:00
|
|
|
|
|
|
|
static get pubsub(): InternalRelay {
|
2024-04-25 23:31:16 +00:00
|
|
|
if (!this._pubsub) {
|
|
|
|
this._pubsub = new InternalRelay();
|
2024-04-25 23:28:19 +00:00
|
|
|
}
|
|
|
|
|
2024-04-25 23:31:16 +00:00
|
|
|
return this._pubsub;
|
2024-04-25 23:28:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-23 23:50:33 +00:00
|
|
|
export { cache, client, eventsDB, optimizer, reqmeister, searchStore };
|