feat(core): optimize query resource lifecycle
This commit is contained in:
1 parent
b4bd6c42a7
commit
295b67dd36
29 files changed
+1857
-335
No files matched your search
@@ -0,0 +1,25 @@
|
||||
import type { QueryTab } from "@/types/database";
|
||||
import { getResultCacheDiagnostics } from "@/lib/tabs/tabResultCache";
|
||||
|
||||
const cancellation = {
|
||||
count: 0,
|
||||
totalLatencyMs: 0,
|
||||
maxLatencyMs: 0,
|
||||
};
|
||||
|
||||
export function recordQueryCancellationLatency(durationMs: number) {
|
||||
cancellation.count += 1;
|
||||
cancellation.totalLatencyMs += durationMs;
|
||||
cancellation.maxLatencyMs = Math.max(cancellation.maxLatencyMs, durationMs);
|
||||
}
|
||||
|
||||
export function resourceLifecycleDiagnostics(tabs: readonly QueryTab[]) {
|
||||
const cache = getResultCacheDiagnostics();
|
||||
return {
|
||||
activeTasks: tabs.filter((tab) => tab.isExecuting || tab.isExplaining || tab.isCancelling).length,
|
||||
cancellationCount: cancellation.count,
|
||||
averageCancellationLatencyMs: cancellation.count ? cancellation.totalLatencyMs / cancellation.count : 0,
|
||||
maxCancellationLatencyMs: cancellation.maxLatencyMs,
|
||||
...cache,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user