perf(mysql): limit large table result memory
This commit is contained in:
32 files changed
+1441
-177
No files matched your search
@@ -15,6 +15,9 @@ const mocks = vi.hoisted(() => ({
|
||||
listIndexes: vi.fn(),
|
||||
ensureConnected: vi.fn(),
|
||||
tableOpenPageSize: 100,
|
||||
infiniteScroll: true,
|
||||
queryResultMaxRowsEnabled: true,
|
||||
queryResultMaxRows: 10_000,
|
||||
tabs: [] as QueryTab[],
|
||||
setTableMeta: vi.fn(),
|
||||
clearInvalidDataTabSort: vi.fn(),
|
||||
@@ -80,7 +83,14 @@ vi.mock("@/stores/queryStore", () => ({
|
||||
}));
|
||||
|
||||
vi.mock("@/stores/settingsStore", () => ({
|
||||
useSettingsStore: () => ({ editorSettings: { tableOpenPageSize: mocks.tableOpenPageSize } }),
|
||||
useSettingsStore: () => ({
|
||||
editorSettings: {
|
||||
tableOpenPageSize: mocks.tableOpenPageSize,
|
||||
infiniteScroll: mocks.infiniteScroll,
|
||||
queryResultMaxRowsEnabled: mocks.queryResultMaxRowsEnabled,
|
||||
queryResultMaxRows: mocks.queryResultMaxRows,
|
||||
},
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("@/composables/useToast", () => ({
|
||||
@@ -118,6 +128,9 @@ describe("useDataGridActions", () => {
|
||||
vi.clearAllMocks();
|
||||
mocks.tabs.length = 0;
|
||||
mocks.tableOpenPageSize = 100;
|
||||
mocks.infiniteScroll = true;
|
||||
mocks.queryResultMaxRowsEnabled = true;
|
||||
mocks.queryResultMaxRows = 10_000;
|
||||
mocks.getConfig.mockReturnValue({ id: "postgres-1", db_type: "postgres" });
|
||||
mocks.buildTableSelectSql.mockResolvedValue("SELECT * FROM public.users LIMIT 100 OFFSET 0");
|
||||
mocks.buildSortedQuerySql.mockResolvedValue({ ok: true, sql: "SELECT sorted" });
|
||||
@@ -160,6 +173,23 @@ describe("useDataGridActions", () => {
|
||||
expect(mocks.executeTabSql.mock.calls[0]?.[2]).not.toHaveProperty("preserveTotalRowCountDuringExecution");
|
||||
});
|
||||
|
||||
it("keeps infinite-scroll appends for ordinary table-data pages", async () => {
|
||||
const tab = tableDataTab({
|
||||
result: {
|
||||
columns: ["id"],
|
||||
rows: Array.from({ length: 100 }, (_, index) => [index + 1]),
|
||||
affected_rows: 0,
|
||||
execution_time_ms: 1,
|
||||
},
|
||||
});
|
||||
mocks.buildTableSelectSql.mockResolvedValueOnce("SELECT * FROM public.users LIMIT 100 OFFSET 100");
|
||||
const actions = useDataGridActions(computed(() => tab));
|
||||
|
||||
await actions.onPaginate(100, 100);
|
||||
|
||||
expect(mocks.executeTabSql).toHaveBeenCalledWith("tab-1", "SELECT * FROM public.users LIMIT 100 OFFSET 100", expect.objectContaining({ appendResult: { maxRows: 10_000 } }));
|
||||
});
|
||||
|
||||
it("ignores a stale structured order when its column was renamed", async () => {
|
||||
const tab = tableDataTab({
|
||||
resultSortColumn: "old_name",
|
||||
|
||||
@@ -243,4 +243,13 @@ describe("useDataGridEditor appendPastedRowsToNewRow", () => {
|
||||
["Grace", null, null],
|
||||
]);
|
||||
});
|
||||
|
||||
it("uses resolved full values instead of preview values when cloning", () => {
|
||||
const editor = createEditor();
|
||||
editor.newRows.value = [["Ada", "preview...", "Lovelace"]];
|
||||
|
||||
editor.cloneRow(-1, new Map([[1, "full payload"]]));
|
||||
|
||||
expect(editor.newRows.value[1]).toEqual(["Ada", "full payload", "Lovelace"]);
|
||||
});
|
||||
});
|
||||
@@ -763,6 +763,103 @@ describe("useDataGridExport prepared row statements", () => {
|
||||
expect(extractDataGridSelection).toHaveBeenNthCalledWith(2, expect.objectContaining({ rows: [[7, { name: "Ada", tags: ["admin"] }]] }));
|
||||
});
|
||||
|
||||
it("resolves large-value previews before building an extractor request", async () => {
|
||||
const matrix: CellSelectionMatrix = {
|
||||
rowIndexes: [0],
|
||||
columnIndexes: [0, 1],
|
||||
columns: ["id", "name"],
|
||||
rows: [[7, "preview..."]],
|
||||
};
|
||||
const item = row([7, "preview..."]);
|
||||
const resolveSourceValues = vi.fn(async () => new Map([[item.id, new Map([[1, "full payload"]])]]));
|
||||
const options: UseDataGridExportOptions = {
|
||||
columns: computed(() => ["id", "name"]),
|
||||
displayItems: computed(() => [item]),
|
||||
allColumns: computed(() => ["id", "name"]),
|
||||
allDisplayItems: computed(() => [item]),
|
||||
visibleColumnIndexes: computed(() => [0, 1]),
|
||||
sql: computed(() => undefined),
|
||||
tableMeta: computed(() => editableTable),
|
||||
databaseType: computed(() => "mysql"),
|
||||
connectionId: computed(() => "connection-1"),
|
||||
database: computed(() => "dbx"),
|
||||
context: computed(() => "table-data"),
|
||||
sourceColumns: computed(() => ["id", "name"]),
|
||||
columnTypes: computed(() => ["int", "varchar"]),
|
||||
whereInput: computed(() => undefined),
|
||||
orderBy: computed(() => undefined),
|
||||
exportBatchSize: computed(() => 1000),
|
||||
hasCellSelection: computed(() => true),
|
||||
selectedCells: computed(() => matrix),
|
||||
selectedCellMatrix: computed(() => matrix),
|
||||
selectedRange: computed(() => ({ startRow: 0, endRow: 0, startCol: 0, endCol: 1 })),
|
||||
contextCell: ref({ rowId: item.id, rowIndex: 0, col: 1 }),
|
||||
contextSelectionIsSynthetic: ref(false),
|
||||
getRowItem: () => item,
|
||||
selectedRowIds: ref(new Set<number>()),
|
||||
hasRowSelection: computed(() => false),
|
||||
resolveSourceValues,
|
||||
};
|
||||
vi.mocked(extractDataGridSelection).mockResolvedValueOnce({
|
||||
text: "copied",
|
||||
mimeType: "text/tab-separated-values",
|
||||
fileExtension: "tsv",
|
||||
rowCount: 1,
|
||||
columnCount: 2,
|
||||
});
|
||||
|
||||
await expect(useDataGridExport(options).copyWithExtractor("tsv")).resolves.toBe(true);
|
||||
|
||||
expect(resolveSourceValues).toHaveBeenCalledWith([item.id], [0, 1]);
|
||||
expect(extractDataGridSelection).toHaveBeenCalledWith(expect.objectContaining({ rows: [[7, "full payload"]] }));
|
||||
});
|
||||
|
||||
it("does not copy a preview when full-value resolution fails", async () => {
|
||||
const matrix: CellSelectionMatrix = {
|
||||
rowIndexes: [0],
|
||||
columnIndexes: [0],
|
||||
columns: ["name"],
|
||||
rows: [["preview..."]],
|
||||
};
|
||||
const item = row(["preview..."]);
|
||||
const state = useDataGridExport({
|
||||
columns: computed(() => ["name"]),
|
||||
displayItems: computed(() => [item]),
|
||||
allColumns: computed(() => ["name"]),
|
||||
allDisplayItems: computed(() => [item]),
|
||||
visibleColumnIndexes: computed(() => [0]),
|
||||
sql: computed(() => undefined),
|
||||
tableMeta: computed(() => editableTable),
|
||||
databaseType: computed(() => "mysql"),
|
||||
connectionId: computed(() => "connection-1"),
|
||||
database: computed(() => "dbx"),
|
||||
context: computed(() => "table-data"),
|
||||
sourceColumns: computed(() => ["name"]),
|
||||
columnTypes: computed(() => ["varchar"]),
|
||||
whereInput: computed(() => undefined),
|
||||
orderBy: computed(() => undefined),
|
||||
exportBatchSize: computed(() => 1000),
|
||||
hasCellSelection: computed(() => true),
|
||||
selectedCells: computed(() => matrix),
|
||||
selectedCellMatrix: computed(() => matrix),
|
||||
selectedRange: computed(() => ({ startRow: 0, endRow: 0, startCol: 0, endCol: 0 })),
|
||||
contextCell: ref({ rowId: item.id, rowIndex: 0, col: 0 }),
|
||||
contextSelectionIsSynthetic: ref(false),
|
||||
getRowItem: () => item,
|
||||
selectedRowIds: ref(new Set<number>()),
|
||||
hasRowSelection: computed(() => false),
|
||||
resolveSourceValues: async () => {
|
||||
throw new Error("stable key required");
|
||||
},
|
||||
});
|
||||
|
||||
await expect(state.copyWithExtractor("tsv")).resolves.toBe(false);
|
||||
|
||||
expect(extractDataGridSelection).not.toHaveBeenCalled();
|
||||
expect(copyToClipboard).not.toHaveBeenCalled();
|
||||
expect(toast).toHaveBeenCalledWith("grid.copyFailed: stable key required", 5000);
|
||||
});
|
||||
|
||||
it("rejects SQL UPDATE instead of silently skipping a row with a null primary key", async () => {
|
||||
const matrix: CellSelectionMatrix = {
|
||||
rowIndexes: [0],
|
||||
|
||||
@@ -212,11 +212,13 @@ describe("useSidebarDataOpenRuntime", () => {
|
||||
await useSidebarDataOpenRuntime().openData(tableNode);
|
||||
mocks.tabs[0]!.isExecuting = false;
|
||||
mocks.tabs[0]!.executionId = undefined;
|
||||
mocks.tabs[0]!.resultLocalSortOriginalLargeValueCells = [{ row_index: 0, column_index: 1, original_bytes: 1_000_000 }];
|
||||
await useSidebarDataOpenRuntime().openData(ordersNode);
|
||||
|
||||
expect(mocks.tabs).toHaveLength(1);
|
||||
expect(mocks.tabs[0]?.title).toBe("orders");
|
||||
expect(mocks.tabs[0]?.tableMeta?.tableName).toBe("orders");
|
||||
expect(mocks.tabs[0]?.resultLocalSortOriginalLargeValueCells).toBeUndefined();
|
||||
});
|
||||
|
||||
it.each([
|
||||
|
||||
@@ -1120,12 +1120,13 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) {
|
||||
return { ok: true, rowCount: mappedRows.length };
|
||||
}
|
||||
|
||||
function clonedRowData(item: RowItem): CellValue[] {
|
||||
function clonedRowData(item: RowItem, resolvedValues?: ReadonlyMap<number, CellValue>): CellValue[] {
|
||||
const columnInfoByName = new Map((tableMeta.value?.columns ?? []).map((column) => [column.name.toLowerCase(), column]));
|
||||
return item.data.map((val, i) => {
|
||||
const columnName = sourceColumns.value?.[i] ?? result.value.columns[i];
|
||||
const columnInfo = columnInfoByName.get(columnName.toLowerCase());
|
||||
return shouldClearClonedColumn(columnName, columnInfo) ? null : val;
|
||||
if (shouldClearClonedColumn(columnName, columnInfo)) return null;
|
||||
return resolvedValues?.has(i) ? (resolvedValues.get(i) ?? null) : val;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1137,10 +1138,10 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) {
|
||||
return /\b(auto_increment|autoincrement|identity|generated)\b/i.test(extra) || /\bnextval\s*\(/i.test(columnDefault);
|
||||
}
|
||||
|
||||
function cloneRow(rowId: number) {
|
||||
function cloneRow(rowId: number, resolvedValues?: ReadonlyMap<number, CellValue>) {
|
||||
const item = getRowItem(rowId);
|
||||
if (!item) return;
|
||||
const clonedData = clonedRowData(item);
|
||||
const clonedData = clonedRowData(item, resolvedValues);
|
||||
pushUndoSnapshot();
|
||||
rowStatusFilter.value = rowStatusFilterAfterAddingRow(rowStatusFilter.value);
|
||||
newRows.value.push(clonedData);
|
||||
@@ -1159,13 +1160,13 @@ export function useDataGridEditor(options: UseDataGridEditorOptions) {
|
||||
});
|
||||
}
|
||||
|
||||
function cloneRows(rowIds: number[]) {
|
||||
function cloneRows(rowIds: number[], resolvedValues?: ReadonlyMap<number, ReadonlyMap<number, CellValue>>) {
|
||||
const rowsToClone = rowIds.map((rowId) => getRowItem(rowId)).filter(Boolean) as RowItem[];
|
||||
if (rowsToClone.length === 0) return;
|
||||
pushUndoSnapshot();
|
||||
rowStatusFilter.value = rowStatusFilterAfterAddingRow(rowStatusFilter.value);
|
||||
for (const item of rowsToClone) {
|
||||
const clonedData = clonedRowData(item);
|
||||
const clonedData = clonedRowData(item, resolvedValues?.get(item.id));
|
||||
newRows.value.push(clonedData);
|
||||
newRowMeta.value.push(clonedRowMeta(item, clonedData));
|
||||
}
|
||||
|
||||
@@ -98,6 +98,7 @@ export interface UseDataGridExportOptions {
|
||||
getRowItem: (rowId: number) => RowItem | undefined;
|
||||
selectedRowIds: Ref<Set<number>> | ComputedRef<Set<number>>;
|
||||
hasRowSelection: ComputedRef<boolean>;
|
||||
resolveSourceValues?: (rowIds: number[], sourceColumnIndexes: number[]) => Promise<Map<number, Map<number, CellValue>>>;
|
||||
fullExportResult?: (onProgress?: (info: { rowsExported: number; totalRows: number | null }) => void) => Promise<QueryResult | undefined>;
|
||||
queryResultExportRequest?: (options: { exportId: string; filePath: string; format: "csv" | "xlsx" | "txt" | "sql"; includeSqlSheet?: boolean; exportTableName?: string; exportColumnTypes?: Array<string | null | undefined> }) => Promise<QueryResultExportRequest | undefined>;
|
||||
/**
|
||||
@@ -182,6 +183,7 @@ export function useDataGridExport(options: UseDataGridExportOptions) {
|
||||
getRowItem,
|
||||
selectedRowIds,
|
||||
hasRowSelection,
|
||||
resolveSourceValues,
|
||||
fullExportResult,
|
||||
queryResultExportRequest,
|
||||
hasCompleteLocalResult,
|
||||
@@ -223,6 +225,25 @@ export function useDataGridExport(options: UseDataGridExportOptions) {
|
||||
return displayItems.value.filter((item) => rowIdSet.has(item.id) && !item.isDraft);
|
||||
}
|
||||
|
||||
async function resolveVisibleRowValues(items: RowItem[], visibleIndexes = visibleColumnIndexes.value): Promise<RowItem[]> {
|
||||
if (!resolveSourceValues || items.length === 0 || visibleIndexes.length === 0) return items;
|
||||
const resolved = await resolveSourceValues(
|
||||
items.map((item) => item.id),
|
||||
visibleIndexes,
|
||||
);
|
||||
if (resolved.size === 0) return items;
|
||||
return items.map((item) => {
|
||||
const values = resolved.get(item.id);
|
||||
if (!values) return item;
|
||||
const data = [...item.data];
|
||||
visibleIndexes.forEach((sourceIndex) => {
|
||||
const visibleIndex = visibleColumnIndexes.value.indexOf(sourceIndex);
|
||||
if (visibleIndex >= 0 && values.has(sourceIndex)) data[visibleIndex] = values.get(sourceIndex) ?? null;
|
||||
});
|
||||
return { ...item, data };
|
||||
});
|
||||
}
|
||||
|
||||
function applyGlobalDateTimeExportFormat(result: { columns: string[]; columnTypes: string[]; rows: CellValue[][] }, enabled: boolean) {
|
||||
const pattern = enabled ? useSettingsStore().editorSettings.globalDateTimeExportFormat : "";
|
||||
return pattern ? { ...result, rows: formatTemporalRowsForExport(result.rows, result.columnTypes, pattern) } : result;
|
||||
@@ -315,7 +336,7 @@ export function useDataGridExport(options: UseDataGridExportOptions) {
|
||||
{
|
||||
columns: columns.value,
|
||||
columnTypes: (columnTypes.value ?? []).map((type) => type ?? ""),
|
||||
rows: rowsToExport(rowIds).map((item) => item.data),
|
||||
rows: (await resolveVisibleRowValues(rowsToExport(rowIds))).map((item) => item.data),
|
||||
},
|
||||
formatDateTime,
|
||||
),
|
||||
@@ -436,7 +457,8 @@ export function useDataGridExport(options: UseDataGridExportOptions) {
|
||||
|
||||
async function copyRowsAsJson(items: RowItem[]) {
|
||||
if (items.length === 0) return;
|
||||
const value = items.length === 1 ? rowToJsonObject(items[0]) : items.map(rowToJsonObject);
|
||||
const resolvedItems = await resolveVisibleRowValues(items);
|
||||
const value = resolvedItems.length === 1 ? rowToJsonObject(resolvedItems[0]) : resolvedItems.map(rowToJsonObject);
|
||||
const hasOriginalMongoDocuments = options.databaseType.value === "mongodb" && items.every((item) => item.sourceIndex !== undefined && options.mongoDocuments?.value?.[item.sourceIndex] !== undefined);
|
||||
const copyValue = options.databaseType.value === "mongodb" && !hasOriginalMongoDocuments ? expandNestedJsonStringsForCopy(value) : value;
|
||||
await copyText(JSON.stringify(copyValue, null, 2));
|
||||
@@ -447,7 +469,9 @@ export function useDataGridExport(options: UseDataGridExportOptions) {
|
||||
if (!contextCell.value || contextCell.value.col < 0) return;
|
||||
const item = getRowItem(contextCell.value.rowId);
|
||||
if (!item || item.isDraft) return;
|
||||
const val = item?.data[contextCell.value.col] ?? null;
|
||||
const sourceIndex = visibleColumnIndexes.value[contextCell.value.col] ?? contextCell.value.col;
|
||||
const [resolvedItem] = await resolveVisibleRowValues([item], [sourceIndex]);
|
||||
const val = resolvedItem?.data[contextCell.value.col] ?? null;
|
||||
await copyText(displayCellValue(val), { rows: [[val]] });
|
||||
}
|
||||
|
||||
@@ -575,6 +599,7 @@ export function useDataGridExport(options: UseDataGridExportOptions) {
|
||||
hasRowSelection,
|
||||
hasColumnSelection,
|
||||
selectedRowIds,
|
||||
resolveSourceValues,
|
||||
copyText,
|
||||
canCopySqlInsert: (request) => {
|
||||
const selectedColumns = request.selectedColumnIndexes.map((index) => request.columns[index]?.sourceName ?? request.columns[index]?.displayName).filter((column): column is string => !!column);
|
||||
@@ -589,7 +614,7 @@ export function useDataGridExport(options: UseDataGridExportOptions) {
|
||||
|
||||
async function copyAll() {
|
||||
const header = columns.value.join("\t");
|
||||
const rows = displayItems.value.filter((item) => !item.isDraft).map((item) => item.data);
|
||||
const rows = (await resolveVisibleRowValues(displayItems.value.filter((item) => !item.isDraft))).map((item) => item.data);
|
||||
const body = rows.map((row) => row.map((cell) => displayCellValue(cell)).join("\t")).join("\n");
|
||||
await copyText(`${header}\n${body}`, { rows, header: columns.value });
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ interface UseDataGridExtractorOptions {
|
||||
hasRowSelection: ComputedRef<boolean>;
|
||||
hasColumnSelection: ComputedRef<boolean>;
|
||||
selectedRowIds: Ref<Set<number>> | ComputedRef<Set<number>>;
|
||||
resolveSourceValues?: (rowIds: number[], sourceColumnIndexes: number[]) => Promise<Map<number, Map<number, unknown>>>;
|
||||
contextCell: ComputedRef<{ rowId: number; rowIndex: number; col: number } | null> | Ref<{ rowId: number; rowIndex: number; col: number } | null>;
|
||||
contextSelectionIsSynthetic: ComputedRef<boolean> | Ref<boolean>;
|
||||
copyText: (text: string, gridCopy?: { rows: readonly (readonly unknown[])[]; header?: readonly unknown[] }) => Promise<boolean>;
|
||||
@@ -58,6 +59,7 @@ export function useDataGridExtractor(options: UseDataGridExtractorOptions) {
|
||||
const { t } = useI18n();
|
||||
const { toast } = useToast();
|
||||
const hasUnsupportedDiscreteSelection = computed(() => options.hasCellSelection.value && options.selectedCellMatrix.value === null);
|
||||
const requestSources = new WeakMap<DataGridExtractRequest, { rowIds: number[]; sourceColumnIndexes: number[]; columnTypes: Array<string | undefined>; normalizeValues: boolean }>();
|
||||
|
||||
function normalizeCellValue(value: unknown, columnType: string | undefined): unknown {
|
||||
if (typeof value !== "string" || columnType?.trim().toLowerCase() !== "json") return value;
|
||||
@@ -82,6 +84,7 @@ export function useDataGridExtractor(options: UseDataGridExtractorOptions) {
|
||||
const fullColumns = options.allColumns.value;
|
||||
const fullItemsById = new Map(options.allDisplayItems.value.map((item) => [item.id, item]));
|
||||
let sourceRows: unknown[][] = [];
|
||||
let sourceRowIds: number[] = [];
|
||||
let selectedSourceIndexes: number[] = [];
|
||||
let selectionKind: DataGridExtractRequest["selectionKind"] = "cells";
|
||||
|
||||
@@ -93,14 +96,15 @@ export function useDataGridExtractor(options: UseDataGridExtractorOptions) {
|
||||
const hasRightClickContext = !!options.contextCell.value && options.contextSelectionIsSynthetic.value;
|
||||
|
||||
if (options.hasRowSelection.value && options.selectedRowIds.value.size > 0) {
|
||||
sourceRows = options.displayItems.value.filter((item) => options.selectedRowIds.value.has(item.id) && !item.isDraft).map((item) => (fullItemsById.get(item.id) ?? item).data);
|
||||
const items = options.displayItems.value.filter((item) => options.selectedRowIds.value.has(item.id) && !item.isDraft);
|
||||
sourceRows = items.map((item) => (fullItemsById.get(item.id) ?? item).data);
|
||||
sourceRowIds = items.map((item) => item.id);
|
||||
selectedSourceIndexes = dedupeColumnIndexes(visibleIndexes).filter((index) => index < fullColumns.length);
|
||||
selectionKind = "rows";
|
||||
} else if (isMultiCellSelection && matrix) {
|
||||
sourceRows = matrix.rowIndexes
|
||||
.map((rowIndex) => options.displayItems.value[rowIndex])
|
||||
.filter((item): item is ExtractorRowItem => !!item && !item.isDraft)
|
||||
.map((item) => (fullItemsById.get(item.id) ?? item).data);
|
||||
const items = matrix.rowIndexes.map((rowIndex) => options.displayItems.value[rowIndex]).filter((item): item is ExtractorRowItem => !!item && !item.isDraft);
|
||||
sourceRows = items.map((item) => (fullItemsById.get(item.id) ?? item).data);
|
||||
sourceRowIds = items.map((item) => item.id);
|
||||
selectedSourceIndexes = dedupeColumnIndexes(matrix.columnIndexes.map((index) => visibleIndexes[index] ?? index)).filter((index) => index < fullColumns.length);
|
||||
if (options.hasColumnSelection.value) selectionKind = "columns";
|
||||
} else if (hasRightClickContext && options.contextCell.value) {
|
||||
@@ -108,15 +112,15 @@ export function useDataGridExtractor(options: UseDataGridExtractorOptions) {
|
||||
const item = fullItemsById.get(options.contextCell.value.rowId);
|
||||
if (item && !item.isDraft) {
|
||||
sourceRows = [item.data];
|
||||
sourceRowIds = [item.id];
|
||||
selectedSourceIndexes = dedupeColumnIndexes(visibleIndexes).filter((index) => index < fullColumns.length);
|
||||
selectionKind = "rows";
|
||||
}
|
||||
} else if (matrix) {
|
||||
// Single-cell matrix without a context cell — still honor the explicit selection.
|
||||
sourceRows = matrix.rowIndexes
|
||||
.map((rowIndex) => options.displayItems.value[rowIndex])
|
||||
.filter((item): item is ExtractorRowItem => !!item && !item.isDraft)
|
||||
.map((item) => (fullItemsById.get(item.id) ?? item).data);
|
||||
const items = matrix.rowIndexes.map((rowIndex) => options.displayItems.value[rowIndex]).filter((item): item is ExtractorRowItem => !!item && !item.isDraft);
|
||||
sourceRows = items.map((item) => (fullItemsById.get(item.id) ?? item).data);
|
||||
sourceRowIds = items.map((item) => item.id);
|
||||
selectedSourceIndexes = dedupeColumnIndexes(matrix.columnIndexes.map((index) => visibleIndexes[index] ?? index)).filter((index) => index < fullColumns.length);
|
||||
if (options.hasColumnSelection.value) selectionKind = "columns";
|
||||
}
|
||||
@@ -146,7 +150,7 @@ export function useDataGridExtractor(options: UseDataGridExtractorOptions) {
|
||||
columns.map((column) => column.sourceName ?? column.displayName),
|
||||
)
|
||||
: undefined;
|
||||
return {
|
||||
const request: DataGridExtractRequest = {
|
||||
version: DATA_GRID_EXTRACTOR_CONTRACT_VERSION,
|
||||
extractor,
|
||||
databaseType: descriptor.category === "sql" ? options.databaseType.value : undefined,
|
||||
@@ -157,6 +161,31 @@ export function useDataGridExtractor(options: UseDataGridExtractorOptions) {
|
||||
selectionKind,
|
||||
options: normalizeDataGridExtractorOptions(extractorOptions),
|
||||
};
|
||||
requestSources.set(request, {
|
||||
rowIds: sourceRowIds,
|
||||
sourceColumnIndexes: requiredSourceIndexes,
|
||||
columnTypes: requiredSourceIndexes.map((sourceIndex) => columnTypesBySource.get(sourceIndex)),
|
||||
normalizeValues: descriptor.category === "json" || descriptor.category === "sql",
|
||||
});
|
||||
return request;
|
||||
}
|
||||
|
||||
async function resolveRequestSourceValues(request: DataGridExtractRequest, rowLimit?: number): Promise<DataGridExtractRequest> {
|
||||
const source = requestSources.get(request);
|
||||
if (!source || !options.resolveSourceValues) return rowLimit === undefined ? request : { ...request, rows: request.rows.slice(0, rowLimit) };
|
||||
const rowIds = rowLimit === undefined ? source.rowIds : source.rowIds.slice(0, rowLimit);
|
||||
const overlays = await options.resolveSourceValues(rowIds, source.sourceColumnIndexes);
|
||||
const rows = request.rows.slice(0, rowIds.length).map((row, rowIndex) => {
|
||||
const values = overlays.get(rowIds[rowIndex]!);
|
||||
if (!values) return row;
|
||||
return row.map((value, compactIndex) => {
|
||||
const sourceIndex = source.sourceColumnIndexes[compactIndex];
|
||||
if (sourceIndex === undefined || !values.has(sourceIndex)) return value;
|
||||
const resolved = values.get(sourceIndex);
|
||||
return source.normalizeValues ? normalizeCellValue(resolved, source.columnTypes[compactIndex]) : resolved;
|
||||
});
|
||||
});
|
||||
return { ...request, rows };
|
||||
}
|
||||
|
||||
function canBuildSqlUpdateRequest(): boolean {
|
||||
@@ -219,9 +248,10 @@ export function useDataGridExtractor(options: UseDataGridExtractorOptions) {
|
||||
return false;
|
||||
}
|
||||
if (!canCopyWithExtractor(extractor, extractorOptions)) return false;
|
||||
const request = buildRequest(extractor, extractorOptions);
|
||||
if (!request) return false;
|
||||
const initialRequest = buildRequest(extractor, extractorOptions);
|
||||
if (!initialRequest) return false;
|
||||
try {
|
||||
const request = await resolveRequestSourceValues(initialRequest);
|
||||
const mongoResult = await resolveMongoExtractorResult(extractor, request);
|
||||
const result = mongoResult ?? (await api.extractDataGridSelection(request));
|
||||
if (!result.text) return false;
|
||||
@@ -253,12 +283,13 @@ export function useDataGridExtractor(options: UseDataGridExtractorOptions) {
|
||||
|
||||
async function previewWithExtractor(extractor: DataGridCopyExtractorId, extractorOptions: DataGridExtractorOptions): Promise<DataGridExtractPreview> {
|
||||
if (hasUnsupportedDiscreteSelection.value) throw new Error(t("grid.copyExtractorUnsupportedSelection"));
|
||||
const request = buildRequest(extractor, extractorOptions);
|
||||
if (!request) throw new Error(t("grid.copyExtractorEmptySelection"));
|
||||
const sourceRowCount = request.rows.length;
|
||||
const initialRequest = buildRequest(extractor, extractorOptions);
|
||||
if (!initialRequest) throw new Error(t("grid.copyExtractorEmptySelection"));
|
||||
const sourceRowCount = initialRequest.rows.length;
|
||||
const previewRowCount = Math.min(sourceRowCount, DATA_GRID_EXTRACTOR_PREVIEW_MAX_ROWS);
|
||||
const request = await resolveRequestSourceValues(initialRequest, previewRowCount);
|
||||
const mongoResult = await resolveMongoExtractorResult(extractor, request, previewRowCount);
|
||||
const result = mongoResult ?? (await api.extractDataGridSelection({ ...request, rows: request.rows.slice(0, DATA_GRID_EXTRACTOR_PREVIEW_MAX_ROWS) }));
|
||||
const result = mongoResult ?? (await api.extractDataGridSelection(request));
|
||||
if (!result.text) throw new Error(t("grid.copyExtractorEmptySelection"));
|
||||
return { ...result, sourceRowCount, truncated: sourceRowCount > result.rowCount };
|
||||
}
|
||||
|
||||
@@ -140,6 +140,7 @@ export function useSidebarDataOpenRuntime() {
|
||||
tab.resultSortDirection = undefined;
|
||||
tab.resultSortMode = undefined;
|
||||
tab.resultLocalSortOriginalRows = undefined;
|
||||
tab.resultLocalSortOriginalLargeValueCells = undefined;
|
||||
tab.resultLocalSortOriginalMongoDocuments = undefined;
|
||||
tab.resultLocalSortOriginalMongoCopyDocuments = undefined;
|
||||
tab.resultSortedSql = undefined;
|
||||
|
||||
Reference in new issue
Block a user