From 520c35db605f8afa1bf521bb0248e86b59128af9 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 27 Dec 2023 16:21:58 -0600 Subject: [PATCH] Add `debug` library, adapt pipeline to it --- src/deps.ts | 2 ++ src/pipeline.ts | 8 +++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/deps.ts b/src/deps.ts index 4a9314b..0f76433 100644 --- a/src/deps.ts +++ b/src/deps.ts @@ -83,5 +83,7 @@ export { sentry as sentryMiddleware } from 'npm:@hono/sentry@^1.0.0'; export * as Comlink from 'npm:comlink@^4.4.1'; export { EventEmitter } from 'npm:tseep@^1.1.3'; export { default as stringifyStable } from 'npm:fast-stable-stringify@^1.0.0'; +// @deno-types="npm:@types/debug@^4.1.12" +export { default as Debug } from 'npm:debug@^4.3.4'; export type * as TypeFest from 'npm:type-fest@^4.3.0'; diff --git a/src/pipeline.ts b/src/pipeline.ts index 923bf4e..2919573 100644 --- a/src/pipeline.ts +++ b/src/pipeline.ts @@ -4,7 +4,7 @@ import * as eventsDB from '@/db/events.ts'; import { addRelays } from '@/db/relays.ts'; import { deleteAttachedMedia } from '@/db/unattached-media.ts'; import { findUser } from '@/db/users.ts'; -import { type Event, LRUCache } from '@/deps.ts'; +import { Debug, type Event, LRUCache } from '@/deps.ts'; import { isEphemeralKind } from '@/kinds.ts'; import * as mixer from '@/mixer.ts'; import { publish } from '@/pool.ts'; @@ -18,6 +18,8 @@ import { verifySignatureWorker } from '@/workers/verify.ts'; import type { EventData } from '@/types.ts'; +const debug = Debug('ditto:pipeline'); + /** * Common pipeline function to process (and maybe store) events. * It is idempotent, so it can be called multiple times for the same event. @@ -26,7 +28,7 @@ async function handleEvent(event: Event): Promise { if (!(await verifySignatureWorker(event))) return; const wanted = reqmeister.isWanted(event); if (encounterEvent(event)) return; - console.info(`pipeline: Event<${event.kind}> ${event.id}`); + debug(`Event<${event.kind}> ${event.id}`); const data = await getEventData(event); await Promise.all([ @@ -115,7 +117,7 @@ async function trackHashtags(event: Event): Promise { if (!tags.length) return; try { - console.info('tracking tags:', tags); + debug('tracking tags:', tags); await TrendsWorker.addTagUsages(event.pubkey, tags, date); } catch (_e) { // do nothing