From 4e999d0f3939a7ef90323797cb61f2ca0bc16b37 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Mon, 8 Apr 2024 08:51:04 -0500 Subject: [PATCH] SqliteWorker: only call perf functions when debugging is enabled --- src/deps.ts | 4 ++-- src/workers/sqlite.worker.ts | 21 +++++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/deps.ts b/src/deps.ts index cceca14..a23fe10 100644 --- a/src/deps.ts +++ b/src/deps.ts @@ -77,8 +77,8 @@ 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'; -export { default as Debug } from 'https://gitlab.com/soapbox-pub/stickynotes/-/raw/v0.2.0/debug.ts'; -export { Stickynotes } from 'https://gitlab.com/soapbox-pub/stickynotes/-/raw/v0.2.0/mod.ts'; +export { default as Debug } from 'https://gitlab.com/soapbox-pub/stickynotes/-/raw/v0.3.0/debug.ts'; +export { Stickynotes } from 'https://gitlab.com/soapbox-pub/stickynotes/-/raw/v0.3.0/mod.ts'; export { LNURL, type LNURLDetails, diff --git a/src/workers/sqlite.worker.ts b/src/workers/sqlite.worker.ts index f608214..c58e8da 100644 --- a/src/workers/sqlite.worker.ts +++ b/src/workers/sqlite.worker.ts @@ -1,10 +1,10 @@ /// import { ScopedPerformance } from 'https://deno.land/x/scoped_performance@v2.0.0/mod.ts'; -import { Comlink, type CompiledQuery, Debug, DenoSqlite3, type QueryResult } from '@/deps.ts'; +import { Comlink, type CompiledQuery, DenoSqlite3, type QueryResult, Stickynotes } from '@/deps.ts'; import '@/sentry.ts'; let db: DenoSqlite3 | undefined; -const debug = Debug('ditto:sqlite.worker'); +const console = new Stickynotes('ditto:sqlite.worker'); export const SqliteWorker = { open(path: string): void { @@ -13,8 +13,11 @@ export const SqliteWorker = { executeQuery({ sql, parameters }: CompiledQuery): QueryResult { if (!db) throw new Error('Database not open'); - const perf = new ScopedPerformance(); - perf.mark('start'); + const perf = (console.enabled && console.level >= 4) ? new ScopedPerformance() : undefined; + + if (perf) { + perf.mark('start'); + } const result = { rows: db!.prepare(sql).all(...parameters as any[]) as R[], @@ -22,11 +25,13 @@ export const SqliteWorker = { insertId: BigInt(db!.lastInsertRowId), }; - const { duration } = perf.measure('end', 'start'); - debug(`${sql} \x1b[90m(${(duration / 1000).toFixed(2)}s)\x1b[0m`); + if (perf) { + const { duration } = perf.measure('end', 'start'); + console.debug(`${sql} \x1b[90m(${(duration / 1000).toFixed(2)}s)\x1b[0m`); - perf.clearMarks(); - perf.clearMeasures(); + perf.clearMarks(); + perf.clearMeasures(); + } return result; },