2024-01-07 20:58:17 +00:00
|
|
|
import { client } from '@/client.ts';
|
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';
|
|
|
|
import { EventsDB } from '@/storages/events-db.ts';
|
|
|
|
import { Memorelay } from '@/storages/memorelay.ts';
|
2024-01-04 06:52:55 +00:00
|
|
|
import { Optimizer } from '@/storages/optimizer.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-01-07 20:54:33 +00:00
|
|
|
import { Time } from '@/utils/time.ts';
|
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. */
|
|
|
|
const memorelay = new Memorelay({ max: 3000 });
|
|
|
|
|
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,
|
|
|
|
cache: memorelay,
|
|
|
|
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-01-07 20:54:33 +00:00
|
|
|
export { eventsDB, memorelay, optimizer, reqmeister, searchStore };
|