From 3d1d56355d9b511be1031a136d5c90989db12df2 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 14 May 2024 18:51:35 -0500 Subject: [PATCH 1/4] Update scripts for async db --- scripts/admin-event.ts | 5 +++-- scripts/admin-role.ts | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/admin-event.ts b/scripts/admin-event.ts index a9939adf..29d3ae2e 100644 --- a/scripts/admin-event.ts +++ b/scripts/admin-event.ts @@ -1,7 +1,7 @@ import { JsonParseStream } from '@std/json/json-parse-stream'; import { TextLineStream } from '@std/streams/text-line-stream'; -import { db } from '@/db.ts'; +import { DittoDB } from '@/db/DittoDB.ts'; import { AdminSigner } from '@/signers/AdminSigner.ts'; import { EventsDB } from '@/storages/events-db.ts'; import { type EventStub } from '@/utils/api.ts'; @@ -9,7 +9,8 @@ import { nostrNow } from '@/utils.ts'; const signer = new AdminSigner(); -const eventsDB = new EventsDB(db); +const kysely = await DittoDB.getInstance(); +const eventsDB = new EventsDB(kysely); const readable = Deno.stdin.readable .pipeThrough(new TextDecoderStream()) diff --git a/scripts/admin-role.ts b/scripts/admin-role.ts index 4fa212e7..57a17e37 100644 --- a/scripts/admin-role.ts +++ b/scripts/admin-role.ts @@ -1,12 +1,13 @@ import { NSchema } from '@nostrify/nostrify'; -import { db } from '@/db.ts'; +import { DittoDB } from '@/db/DittoDB.ts'; import { Conf } from '@/config.ts'; import { AdminSigner } from '@/signers/AdminSigner.ts'; import { EventsDB } from '@/storages/events-db.ts'; import { nostrNow } from '@/utils.ts'; -const eventsDB = new EventsDB(db); +const kysely = await DittoDB.getInstance(); +const eventsDB = new EventsDB(kysely); const [pubkey, role] = Deno.args; From d3a7f0849f0026ed40f18b28bee145d01fa98c6e Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 14 May 2024 19:02:15 -0500 Subject: [PATCH 2/4] deno lint --- src/controllers/api/statuses.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/api/statuses.ts b/src/controllers/api/statuses.ts index a52a4088..98173b0b 100644 --- a/src/controllers/api/statuses.ts +++ b/src/controllers/api/statuses.ts @@ -1,4 +1,4 @@ -import { NostrEvent, NostrFilter, NSchema as n } from '@nostrify/nostrify'; +import { NostrEvent, NSchema as n } from '@nostrify/nostrify'; import ISO6391 from 'iso-639-1'; import { z } from 'zod'; From 477ee8b124f2fddd12e3e0d8c44cd453837ad350 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 14 May 2024 19:09:25 -0500 Subject: [PATCH 3/4] Fix hydrateEvents in streaming --- src/controllers/api/streaming.ts | 7 ++++--- src/controllers/api/timelines.ts | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/controllers/api/streaming.ts b/src/controllers/api/streaming.ts index e79c51eb..1de7bbf7 100644 --- a/src/controllers/api/streaming.ts +++ b/src/controllers/api/streaming.ts @@ -68,15 +68,16 @@ const streamingController: AppController = (c) => { if (!filter) return; try { - const store = await Storages.pubsub(); + const db = await Storages.db(); + const pubsub = await Storages.pubsub(); - for await (const msg of store.req([filter], { signal: controller.signal })) { + for await (const msg of pubsub.req([filter], { signal: controller.signal })) { if (msg[0] === 'EVENT') { const event = msg[2]; await hydrateEvents({ events: [event], - store, + store: db, signal: AbortSignal.timeout(1000), }); diff --git a/src/controllers/api/timelines.ts b/src/controllers/api/timelines.ts index e83c50cd..8ea66baf 100644 --- a/src/controllers/api/timelines.ts +++ b/src/controllers/api/timelines.ts @@ -62,7 +62,7 @@ async function renderStatuses(c: AppContext, filters: NostrFilter[]) { return renderReblog(event, { viewerPubkey }); } return renderStatus(event, { viewerPubkey }); - }))).filter((boolean) => boolean); + }))).filter(Boolean); if (!statuses.length) { return c.json([]); From 2fd50261f9b1032ae64614d49a410302eb9c8074 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 14 May 2024 19:11:38 -0500 Subject: [PATCH 4/4] streaming: actually hydrate with optimizer --- src/controllers/api/streaming.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/api/streaming.ts b/src/controllers/api/streaming.ts index 1de7bbf7..ff47c07d 100644 --- a/src/controllers/api/streaming.ts +++ b/src/controllers/api/streaming.ts @@ -68,8 +68,8 @@ const streamingController: AppController = (c) => { if (!filter) return; try { - const db = await Storages.db(); const pubsub = await Storages.pubsub(); + const optimizer = await Storages.optimizer(); for await (const msg of pubsub.req([filter], { signal: controller.signal })) { if (msg[0] === 'EVENT') { @@ -77,7 +77,7 @@ const streamingController: AppController = (c) => { await hydrateEvents({ events: [event], - store: db, + store: optimizer, signal: AbortSignal.timeout(1000), });