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:
commit
96887483e8
|
@ -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,
|
||||
|
|
|
@ -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();
|
||||
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;
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue