Merge branch 'perf-enabled' into 'main'

SqliteWorker: only call perf functions when debugging is enabled

See merge request soapbox-pub/ditto!142
This commit is contained in:
Alex Gleason 2024-04-08 13:52:57 +00:00
commit 96887483e8
2 changed files with 15 additions and 10 deletions

View File

@ -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,

View File

@ -1,10 +1,10 @@
/// <reference lib="webworker" />
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<R>({ sql, parameters }: CompiledQuery): QueryResult<R> {
if (!db) throw new Error('Database not open');
const perf = new ScopedPerformance();
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),
};
if (perf) {
const { duration } = perf.measure('end', 'start');
debug(`${sql} \x1b[90m(${(duration / 1000).toFixed(2)}s)\x1b[0m`);
console.debug(`${sql} \x1b[90m(${(duration / 1000).toFixed(2)}s)\x1b[0m`);
perf.clearMarks();
perf.clearMeasures();
}
return result;
},