feat(desktop): group partition tables in object browser

This commit is contained in:
t8y2 committed 2026-05-30 11:11:06 +08:00
1 parent 742283bada
commit 99ebecf473
6 files changed
+151 -11

No files matched your search

+39 -1
View File
@@ -9,6 +9,8 @@ export type ObjectBrowserRow = {
comment?: string | null;
created_at?: string | null;
updated_at?: string | null;
partitionParentId?: string;
partitionCount?: number;
};
export type ObjectBrowserSortKey = "name" | "type" | "created_at" | "updated_at" | "comment";
@@ -29,7 +31,7 @@ export function buildObjectBrowserRows(options: {
needsSchema: boolean;
}): ObjectBrowserRow[] {
const seen = new Map<string, number>();
return options.objects.flatMap((object) => {
const rows = options.objects.flatMap((object) => {
const name = normalizeDatabaseObjectName(object.name);
if (!name) return [];
const objectSchema = object.schema ? normalizeDatabaseObjectName(object.schema) : undefined;
@@ -50,6 +52,42 @@ export function buildObjectBrowserRows(options: {
},
];
});
markPartitionRows(rows, options.fallbackSchema || options.database);
return rows;
}
function markPartitionRows(rows: ObjectBrowserRow[], fallbackSchema: string) {
const tableByKey = new Map<string, ObjectBrowserRow>();
for (const row of rows) {
if (row.type !== "TABLE") continue;
tableByKey.set(objectKey(row, fallbackSchema), row);
}
const partitionCountByParent = new Map<string, number>();
for (const row of rows) {
if (row.type !== "TABLE") continue;
const parentName = partitionParentName(row.name);
if (!parentName) continue;
const parentKey = objectKey({ ...row, name: parentName }, fallbackSchema);
const parent = tableByKey.get(parentKey);
if (!parent || parent.id === row.id) continue;
row.partitionParentId = parent.id;
partitionCountByParent.set(parent.id, (partitionCountByParent.get(parent.id) ?? 0) + 1);
}
for (const row of rows) {
row.partitionCount = partitionCountByParent.get(row.id);
}
}
function objectKey(row: Pick<ObjectBrowserRow, "schema" | "name" | "type">, fallbackSchema: string) {
return `${row.type}\0${(row.schema || fallbackSchema).toLowerCase()}\0${row.name.toLowerCase()}`;
}
function partitionParentName(name: string): string | null {
const match = /^(.*)_p\d{4,}$/.exec(name);
return match?.[1] || null;
}
export function filterObjectBrowserRows(rows: ObjectBrowserRow[], query: string): ObjectBrowserRow[] {