Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(grid): keep header index badges stable on refresh

Xsyl.way15d02fa1c1d3
diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vue
index a6ebdcf45b..5924e97726 100644
--- a/apps/desktop/src/components/grid/DataGrid.vue
+++ b/apps/desktop/src/components/grid/DataGrid.vue
@@ -400,7 +400,7 @@ import { constraintsForConstraintsTab } from "@/lib/table/constraintPresentation
import { filterObjectBrowserTableColumns } from "@/lib/table/objectBrowserTableInfo";
import { gaussdbMTypeDisplayName } from "@/lib/table/postgresDataTypeHelp";
import { reserveDataGridHeaderLine } from "@/lib/dataGrid/dataGridHeaderLayout";
-import { buildColumnIndexMap, columnIndexColorClass, columnIndexNameKey, type ColumnIndexKind } from "@/lib/dataGrid/dataGridColumnIndexIcon";
+import { buildColumnIndexMap, columnIndexCacheAction, columnIndexColorClass, columnIndexNameKey, type ColumnIndexKind } from "@/lib/dataGrid/dataGridColumnIndexIcon";
import { isSchemaAware, supportsTableStructureEditing } from "@/lib/database/databaseCapabilities";
import { rememberDataGridConditionHistory } from "@/lib/dataGrid/dataGridConditionHistory";
import { buildDataGridLocalFilterOptions, restoreDataGridLocalColumnFilters, type DataGridLocalFilterOption } from "@/lib/dataGrid/dataGridLocalColumnFilterState";
@@ -12589,6 +12589,10 @@ async function refreshActiveTableInfo() {
}
}
+// 手动刷新会重新发布 tableMeta(例如 catalog/database 从 undefined 变成具体值),
+// 但表身份没有变化。此时清空 indexes 会让表头索引标识闪断(#12093),所以同表刷新
+// 只把缓存标记为过期、保留当前标识直到新结果返回,只有真正切换表才清空。
+let lastMetadataIndexTableIdentity = currentIndexTableIdentity.value;
watch(
() => [props.connectionId, props.database, props.tableMeta?.database, props.tableMeta?.catalog, props.tableMeta?.schema, props.tableMeta?.tableName],
() => {
@@ -12605,11 +12609,18 @@ watch(
tableOverviewLoaded.value = false;
tableOverviewRequestGeneration.value += 1;
rawDdlContent.value = "";
- indexes.value = [];
- indexesLoaded.value = false;
- indexesLoading.value = false;
- indexesError.value = "";
- indexesRequestGeneration.value += 1;
+ const indexTableIdentity = currentIndexTableIdentity.value;
+ const indexCacheAction = columnIndexCacheAction(lastMetadataIndexTableIdentity, indexTableIdentity, indexesLoaded.value);
+ lastMetadataIndexTableIdentity = indexTableIdentity;
+ if (indexCacheAction === "reset") {
+ indexes.value = [];
+ indexesLoaded.value = false;
+ indexesLoading.value = false;
+ indexesError.value = "";
+ indexesRequestGeneration.value += 1;
+ } else if (indexCacheAction === "keep-refresh") {
+ indexesLoaded.value = false;
+ }
foreignKeys.value = [];
foreignKeysLoaded.value = false;
foreignKeysLoading.value = false;
diff --git a/apps/desktop/src/lib/__tests__/dataGrid/dataGridColumnIndexIcon.spec.ts b/apps/desktop/src/lib/__tests__/dataGrid/dataGridColumnIndexIcon.spec.ts
index 9125db0e35..0e2ed7207c 100644
--- a/apps/desktop/src/lib/__tests__/dataGrid/dataGridColumnIndexIcon.spec.ts
+++ b/apps/desktop/src/lib/__tests__/dataGrid/dataGridColumnIndexIcon.spec.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
-import { buildColumnIndexMap, columnIndexMetadataRequestCurrent, columnIndexNameKey, columnIndexTableIdentity } from "@/lib/dataGrid/dataGridColumnIndexIcon";
+import { buildColumnIndexMap, columnIndexCacheAction, columnIndexMetadataRequestCurrent, columnIndexNameKey, columnIndexTableIdentity } from "@/lib/dataGrid/dataGridColumnIndexIcon";
import type { IndexInfo } from "@/types/database";
function indexInfo(overrides: Partial<IndexInfo>): IndexInfo {
@@ -68,3 +68,32 @@ describe("column index metadata request guard", () => {
).toBe(false);
});
});
+
+describe("column index cache action", () => {
+ const users = columnIndexTableIdentity({
+ connectionId: "c1",
+ database: "db",
+ schema: "public",
+ tableName: "users",
+ });
+ const orders = columnIndexTableIdentity({
+ connectionId: "c1",
+ database: "db",
+ schema: "public",
+ tableName: "orders",
+ });
+
+ it("resets only when the table actually changes", () => {
+ expect(columnIndexCacheAction(users, orders, true)).toBe("reset");
+ expect(columnIndexCacheAction(undefined, users, false)).toBe("reset");
+ });
+
+ it("keeps loaded indexes visible while the same table refreshes", () => {
+ // 手动刷新重新发布 tableMeta 时不能清空索引,否则表头标识会闪断(#12093)。
+ expect(columnIndexCacheAction(users, users, true)).toBe("keep-refresh");
+ });
+
+ it("does nothing while the same table's first load is still pending", () => {
+ expect(columnIndexCacheAction(users, users, false)).toBe("unchanged");
+ });
+});
diff --git a/apps/desktop/src/lib/dataGrid/dataGridColumnIndexIcon.ts b/apps/desktop/src/lib/dataGrid/dataGridColumnIndexIcon.ts
index e88e21046e..6583b2b732 100644
--- a/apps/desktop/src/lib/dataGrid/dataGridColumnIndexIcon.ts
+++ b/apps/desktop/src/lib/dataGrid/dataGridColumnIndexIcon.ts
@@ -37,6 +37,20 @@ export function columnIndexMetadataRequestCurrent(options: { requestGeneration:
return options.requestGeneration === options.currentGeneration && options.requestIdentity === options.currentIdentity;
}
+/** How the cached column-index metadata reacts to a table identity update. */
+export type ColumnIndexCacheAction = "reset" | "keep-refresh" | "unchanged";
+
+/**
+ * Keeps the header index badges stable while the same table's metadata is refreshed
+ * (issue #12093): a manual refresh re-publishes `tableMeta`, and clearing the cached
+ * indexes there made the badges blink until the new `listIndexes` result arrived.
+ * Only a real table switch resets them.
+ */
+export function columnIndexCacheAction(previousIdentity: string | undefined, nextIdentity: string | undefined, loaded: boolean): ColumnIndexCacheAction {
+ if (previousIdentity !== nextIdentity) return "reset";
+ return loaded ? "keep-refresh" : "unchanged";
+}
+
function columnIndexPriority(kind: ColumnIndexKind): number {
switch (kind) {
case "primary":