Skip to content

Commit

Permalink
fix (#758)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarasglek authored Dec 1, 2024
1 parent 32f5ed9 commit c348a48
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/lib/performance.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { useLiveQuery } from "dexie-react-hooks";

const PERF_PREFIX = "--chatcraft-";

type PerfStats = {
Expand Down Expand Up @@ -51,8 +53,6 @@ export function getPerformanceStats(): Map<string, PerfStats> {
return new Map(measurements);
}

import { useLiveQuery } from "dexie-react-hooks";

/**
* A custom React hook that wraps useLiveQuery with performance tracing.
* Measures execution time of the query function.
Expand Down Expand Up @@ -94,7 +94,11 @@ export async function measure<T>(name: string, fn: () => Promise<T>): Promise<T>
try {
const result = await fn();
performance.mark(endMark);
performance.measure(fullName, startMark, endMark);
try {
performance.measure(fullName, startMark, endMark);
} catch (e) {
console.error(`Failed to measure ${startMark} to ${endMark}: ${e}`);
}
return result;
} finally {
performance.clearMarks(startMark);
Expand Down

0 comments on commit c348a48

Please sign in to comment.