fix(metadata): bound cache maintenance and pool recovery

This commit is contained in:
miracle authored and GitHub committed 2026-08-19 11:10:12 +08:00
1 parent 21af5cf600
commit 8c2b232243
41 files changed
+2747 -350

No files matched your search

@@ -0,0 +1,19 @@
import { beforeEach, describe, expect, it } from "vitest";
import { resourceLifecycleDiagnostics } from "@/lib/diagnostics/resourceLifecycleDiagnostics";
import { clearMetadataRuntimeCache, setMetadataRuntimeCache } from "@/lib/metadata/metadataRuntimeCache";
describe("resourceLifecycleDiagnostics", () => {
beforeEach(() => {
clearMetadataRuntimeCache();
});
it("includes metadata cache diagnostics in the existing lifecycle snapshot", () => {
setMetadataRuntimeCache("metadata-key", { value: 1 }, "connection-1");
const diagnostics = resourceLifecycleDiagnostics([]);
expect(diagnostics.metadataCache.entries).toBe(1);
expect(diagnostics.metadataCache.bytes).toBeGreaterThan(0);
});
});
@@ -1,5 +1,6 @@
import type { QueryTab } from "@/types/database";
import { getResultCacheDiagnostics } from "@/lib/tabs/tabResultCache";
import { getMetadataRuntimeCacheDiagnostics } from "@/lib/metadata/metadataRuntimeCache";
const cancellation = {
count: 0,
@@ -15,11 +16,13 @@ export function recordQueryCancellationLatency(durationMs: number) {
export function resourceLifecycleDiagnostics(tabs: readonly QueryTab[]) {
const cache = getResultCacheDiagnostics();
const metadataCache = getMetadataRuntimeCacheDiagnostics();
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,
metadataCache,
};
}