mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 03:19:46 +00:00
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { Semaphore } from '@core/asyncutil';
|
|
import { NostrEvent } from '@nostrify/nostrify';
|
|
|
|
import { DittoConf } from '@ditto/conf';
|
|
import { DittoPolyPg } from '@ditto/db';
|
|
|
|
import { DittoPgStore } from '../packages/ditto/storages/DittoPgStore.ts';
|
|
import { DittoRelayStore } from '../packages/ditto/storages/DittoRelayStore.ts';
|
|
|
|
const conf = new DittoConf(Deno.env);
|
|
const db = new DittoPolyPg(conf.databaseUrl);
|
|
|
|
const pgstore = new DittoPgStore({ db, pubkey: await conf.signer.getPublicKey() });
|
|
const relaystore = new DittoRelayStore({ conf, db, relay: pgstore });
|
|
|
|
const sem = new Semaphore(5);
|
|
|
|
const query = db.kysely
|
|
.selectFrom('nostr_events')
|
|
.select(['id', 'kind', 'content', 'pubkey', 'tags', 'created_at', 'sig'])
|
|
.where('kind', '=', 0);
|
|
|
|
for await (const row of query.stream(100)) {
|
|
while (sem.locked) {
|
|
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
}
|
|
|
|
sem.lock(async () => {
|
|
const event: NostrEvent = { ...row, created_at: Number(row.created_at) };
|
|
await relaystore.updateAuthorData(event, AbortSignal.timeout(3000));
|
|
});
|
|
}
|
|
|
|
Deno.exit();
|