From e121a8805e290e7bbf5802b2d29df5b18495798d Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 27 Dec 2023 19:48:48 -0600 Subject: [PATCH] debug: pool, db/events --- src/db/events.ts | 9 ++++++++- src/pool.ts | 5 ++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/db/events.ts b/src/db/events.ts index 9de8828..6eae0f0 100644 --- a/src/db/events.ts +++ b/src/db/events.ts @@ -1,5 +1,5 @@ import { db, type DittoDB } from '@/db.ts'; -import { type Event, type SelectQueryBuilder } from '@/deps.ts'; +import { Debug, type Event, type SelectQueryBuilder } from '@/deps.ts'; import { isParameterizedReplaceableKind } from '@/kinds.ts'; import { jsonMetaContentSchema } from '@/schemas/nostr.ts'; import { EventData } from '@/types.ts'; @@ -7,6 +7,8 @@ import { isNostrId, isURL } from '@/utils.ts'; import type { DittoFilter, GetFiltersOpts } from '@/filter.ts'; +const debug = Debug('ditto:db:events'); + /** Function to decide whether or not to index a tag. */ type TagCondition = ({ event, count, value }: { event: Event; @@ -28,6 +30,8 @@ const tagConditions: Record = { /** Insert an event (and its tags) into the database. */ function insertEvent(event: Event, data: EventData): Promise { + debug('insertEvent', event); + return db.transaction().execute(async (trx) => { /** Insert the event into the database. */ async function addEvent() { @@ -224,6 +228,7 @@ async function getFilters( opts: GetFiltersOpts = {}, ): Promise[]> { if (!filters.length) return Promise.resolve([]); + debug('getFilters', JSON.stringify(filters)); let query = getFiltersQuery(filters); if (typeof opts.limit === 'number') { @@ -276,6 +281,7 @@ async function getFilters( /** Delete events based on filters from the database. */ function deleteFilters(filters: DittoFilter[]) { if (!filters.length) return Promise.resolve([]); + debug('deleteFilters', JSON.stringify(filters)); return db.transaction().execute(async (trx) => { const query = getFiltersQuery(filters).clearSelect().select('id'); @@ -293,6 +299,7 @@ function deleteFilters(filters: DittoFilter[]) { /** Get number of events that would be returned by filters. */ async function countFilters(filters: DittoFilter[]): Promise { if (!filters.length) return Promise.resolve(0); + debug('countFilters', JSON.stringify(filters)); const query = getFiltersQuery(filters); const [{ count }] = await query diff --git a/src/pool.ts b/src/pool.ts index 07ac6b6..8cab8d1 100644 --- a/src/pool.ts +++ b/src/pool.ts @@ -1,5 +1,7 @@ import { getActiveRelays } from '@/db/relays.ts'; -import { type Event, RelayPool } from '@/deps.ts'; +import { Debug, type Event, RelayPool } from '@/deps.ts'; + +const debug = Debug('ditto:pool'); const activeRelays = await getActiveRelays(); @@ -14,6 +16,7 @@ const pool = new RelayPool(activeRelays, { /** Publish an event to the given relays, or the entire pool. */ function publish(event: Event, relays: string[] = activeRelays) { + debug('publish', event); return pool.publish(event, relays); }