perf(sidebar): reduce saved SQL tree and export metadata work
This commit is contained in:
4 files changed
+47
-13
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildDatabaseSavedSqlRootNode, decorateDatabaseSavedSqlTreeNodes, indexSavedSqlFilesByDatabase, savedSqlFilesForDatabase, stripDatabaseSavedSqlTreeNodes } from "@/lib/savedSql/savedSqlDatabaseTree";
|
||||
import { buildDatabaseSavedSqlRootNode, decorateDatabaseSavedSqlTreeNodes, indexSavedSqlFilesByDatabase, savedSqlFilesForDatabase, stripDatabaseSavedSqlTreeNodes, withDatabaseSavedSqlRoot } from "@/lib/savedSql/savedSqlDatabaseTree";
|
||||
import type { SavedSqlFile, TreeNode } from "@/types/database";
|
||||
|
||||
function file(input: Partial<SavedSqlFile> & Pick<SavedSqlFile, "id" | "name" | "connectionId" | "database">): SavedSqlFile {
|
||||
@@ -87,6 +87,16 @@ describe("database saved SQL tree", () => {
|
||||
expect(decorated[0].children?.at(-1)).toMatchObject({ isExpanded: false, children: [{ savedSqlId: "orders-2" }, { savedSqlId: "orders-10" }] });
|
||||
});
|
||||
|
||||
it("reuses unchanged database children when the saved SQL index changes elsewhere", () => {
|
||||
const existingChildren = [{ id: "conn-1:app:tables", label: "tree.tables", type: "group-tables" as const }];
|
||||
const existing = { ...database, children: [...existingChildren, buildDatabaseSavedSqlRootNode(database, files)!] };
|
||||
const next = withDatabaseSavedSqlRoot({ ...database, children: existing.children }, existing.children, indexSavedSqlFilesByDatabase([...files, file({ id: "analytics-2", name: "analytics-2.sql", connectionId: "conn-1", database: "analytics" })]));
|
||||
|
||||
expect(next).toEqual(existing.children);
|
||||
expect(next[0]).toBe(existingChildren[0]);
|
||||
expect(next[1]).toBe(existing.children[1]);
|
||||
});
|
||||
|
||||
it("removes runtime saved SQL nodes before metadata is cached", () => {
|
||||
const decorated = decorateDatabaseSavedSqlTreeNodes([database], files);
|
||||
expect(stripDatabaseSavedSqlTreeNodes(decorated)).toEqual([{ ...database, children: [] }]);
|
||||
|
||||
Reference in new issue
Block a user