mirror of
https://github.com/t8y2/dbx.git
synced 2026-11-01 00:25:38 +00:00
fix(app): dedupe tree object counts
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
export const SCHEMA_TREE_CACHE_TTL_MS = 15 * 60 * 1000;
|
||||
|
||||
export interface SchemaTreeCacheEnvelope<T> {
|
||||
version: 1;
|
||||
version: 2;
|
||||
cachedAt: string;
|
||||
children: T;
|
||||
}
|
||||
@@ -13,7 +13,7 @@ export interface DecodedSchemaTreeCache<T> {
|
||||
|
||||
export function encodeSchemaTreeCache<T>(children: T, nowMs = Date.now()): SchemaTreeCacheEnvelope<T> {
|
||||
return {
|
||||
version: 1,
|
||||
version: 2,
|
||||
cachedAt: new Date(nowMs).toISOString(),
|
||||
children,
|
||||
};
|
||||
@@ -31,7 +31,7 @@ export function decodeSchemaTreeCache<T>(
|
||||
if (!payload || typeof payload !== "object") return null;
|
||||
|
||||
const envelope = payload as Partial<SchemaTreeCacheEnvelope<unknown>>;
|
||||
if (envelope.version !== 1 || !Array.isArray(envelope.children) || typeof envelope.cachedAt !== "string") {
|
||||
if (envelope.version !== 2 || !Array.isArray(envelope.children) || typeof envelope.cachedAt !== "string") {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -96,10 +96,15 @@ export function buildGroupedObjectTreeNodes({
|
||||
objects: ObjectInfo[];
|
||||
}): TreeNode[] {
|
||||
const buckets = new Map<string, ObjectInfo[]>();
|
||||
const seen = new Set<string>();
|
||||
for (const obj of objects) {
|
||||
const name = normalizeDatabaseObjectName(obj.name);
|
||||
if (!name) continue;
|
||||
const t = normalizeObjectType(obj.object_type);
|
||||
const objectSchema = obj.schema ? normalizeDatabaseObjectName(obj.schema) : schema || "";
|
||||
const key = `${t}\0${objectSchema.toLowerCase()}\0${name.toLowerCase()}`;
|
||||
if (seen.has(key)) continue;
|
||||
seen.add(key);
|
||||
const arr = buckets.get(t) ?? [];
|
||||
arr.push({ ...obj, name, schema: obj.schema ? normalizeDatabaseObjectName(obj.schema) : obj.schema });
|
||||
buckets.set(t, arr);
|
||||
|
||||
Reference in New Issue
Block a user