fix(data): use saved row limit for table opens

This commit is contained in:
t8y2 2026-07-03 13:59:34 +08:00
parent 21cec24e75
commit 1ff3676531
6 changed files with 19 additions and 12 deletions

View File

@ -1122,7 +1122,7 @@ async function openData() {
const querySchema = connectionObjectTreeQuerySchema(config, node.database, tableSchema);
const effectiveDbType = effectiveDatabaseTypeForConnection(config);
const limit = tableOpenPageLimit();
const limit = tableOpenPageLimit(settingsStore.editorSettings.pageSize);
const refreshTableMetaInBackground = async () => {
const metadataStartedAt = performance.now();
console.info("[DBX][openData:metadata:start]", {

View File

@ -22,7 +22,7 @@ async function openTableTarget(target: NavigationTarget, options: { tableInfoTab
const connectionStore = useConnectionStore();
const queryStore = useQueryStore();
const settingsStore = useSettingsStore();
const pageLimit = tableOpenPageLimit();
const pageLimit = tableOpenPageLimit(settingsStore.editorSettings.pageSize);
connectionStore.activeConnectionId = target.connectionId;
const config = connectionStore.getConfig(target.connectionId);

View File

@ -2,7 +2,7 @@ import { DEFAULT_RESULT_PAGE_SIZE, normalizeResultPageSize } from "@/lib/paginat
export const DEFAULT_TABLE_OPEN_PAGE_LIMIT = DEFAULT_RESULT_PAGE_SIZE;
export function tableOpenPageLimit(): number {
// Opening a table should not inherit the mutable SQL result-grid rows-per-page setting.
return normalizeResultPageSize(DEFAULT_TABLE_OPEN_PAGE_LIMIT);
export function tableOpenPageLimit(preferredLimit?: unknown): number {
// Data tabs should reopen with the rows-per-page preference the grid persists.
return normalizeResultPageSize(preferredLimit, DEFAULT_TABLE_OPEN_PAGE_LIMIT);
}

View File

@ -2058,7 +2058,7 @@ export const useQueryStore = defineStore("query", () => {
countSql = plan.countSql;
useAgentResultSession = plan.useAgentResultSession;
} else if (tab.mode === "data") {
pageLimit = options?.pagination?.limit ?? tableOpenPageLimit();
pageLimit = options?.pagination?.limit ?? tableOpenPageLimit(settingsStore.editorSettings.pageSize);
pageOffset = options?.pagination?.offset ?? 0;
}
@ -2539,7 +2539,7 @@ export const useQueryStore = defineStore("query", () => {
pagination:
tab.mode === "data"
? {
limit: tab.resultPageLimit ?? tableOpenPageLimit(),
limit: tab.resultPageLimit ?? tableOpenPageLimit(useSettingsStore().editorSettings.pageSize),
offset: tab.resultPageOffset ?? 0,
}
: undefined,

View File

@ -1916,7 +1916,7 @@ test("data tab execution preserves pagination offset metadata", async () => {
}
});
test("data tab default pagination is independent from query result page size", async () => {
test("data tab default pagination follows persisted rows-per-page", async () => {
const restoreStorage = installMemoryStorage();
setActivePinia(createPinia());
const connectionStore = useConnectionStore();
@ -1949,12 +1949,12 @@ test("data tab default pagination is independent from query result page size", a
});
try {
await store.executeTabSql(tabId, 'SELECT * FROM "users" LIMIT 100;');
await store.executeTabSql(tabId, 'SELECT * FROM "users" LIMIT 1000;');
assert.equal(preparedPagination, false);
assert.equal(executeBody.maxRows, 100);
assert.equal(executeBody.fetchSize, 100);
assert.equal(tab.resultPageLimit, 100);
assert.equal(executeBody.maxRows, 1000);
assert.equal(executeBody.fetchSize, 1000);
assert.equal(tab.resultPageLimit, 1000);
assert.equal(tab.resultPageOffset, 0);
} finally {
globalThis.fetch = originalFetch;

View File

@ -4,6 +4,7 @@ import { createPinia, setActivePinia } from "pinia";
import { DEFAULT_SQL_FORMATTER_SETTINGS } from "../../apps/desktop/src/lib/sqlFormatterConfig.ts";
import { DEFAULT_TABLE_COLUMN_TEMPLATE_FIELDS } from "../../apps/desktop/src/lib/tableColumnTemplates.ts";
import { DEFAULT_UI_FONT_FAMILY, SYSTEM_UI_FONT_FAMILY } from "../../apps/desktop/src/lib/appFonts.ts";
import { tableOpenPageLimit } from "../../apps/desktop/src/lib/tableOpenPageLimit.ts";
import { AI_PROVIDER_PRESETS, DEFAULT_EDITOR_SETTINGS, normalizeAiConfig, normalizeEditorSettings, useSettingsStore } from "../../apps/desktop/src/stores/settingsStore.ts";
const OLD_FONT_SIZE_KEY = "dbx-query-editor-font-size";
@ -47,6 +48,12 @@ test("normalizes saved query result page size", () => {
assert.equal(normalizeEditorSettings({ pageSize: 0 }).pageSize, 100);
});
test("uses saved rows-per-page for table opens", () => {
assert.equal(tableOpenPageLimit(), 100);
assert.equal(tableOpenPageLimit(500), 500);
assert.equal(tableOpenPageLimit(0), 100);
});
test("defaults export batch size to 2000 rows", () => {
assert.equal(DEFAULT_EDITOR_SETTINGS.exportBatchSize, 2000);
assert.equal(normalizeEditorSettings({}).exportBatchSize, 2000);