Skip to content

Commit cda5c96

Browse files
committed
fix: performance issues
1 parent 3513f77 commit cda5c96

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

src/components/QueryResultTable/QueryResultTable.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,32 +81,38 @@ interface QueryResultTableProps
8181
}
8282

8383
export const QueryResultTable = (props: QueryResultTableProps) => {
84-
const {columns: rawColumns, data, ...restProps} = props;
84+
const {columns, data, settings: propsSettings} = props;
8585

86-
const columns = React.useMemo(() => {
87-
return rawColumns ? prepareTypedColumns(rawColumns, data) : prepareGenericColumns(data);
88-
}, [data, rawColumns]);
86+
const preparedColumns = React.useMemo(() => {
87+
return columns ? prepareTypedColumns(columns, data) : prepareGenericColumns(data);
88+
}, [data, columns]);
89+
90+
const settings = React.useMemo(() => {
91+
return {
92+
...TABLE_SETTINGS,
93+
...propsSettings,
94+
};
95+
}, [propsSettings]);
8996

9097
// empty data is expected to be be an empty array
9198
// undefined data is not rendered at all
9299
if (!Array.isArray(data)) {
93100
return null;
94101
}
95102

96-
if (!columns.length) {
103+
if (!preparedColumns.length) {
97104
return <div className={b('message')}>{i18n('empty')}</div>;
98105
}
99106

100107
return (
101108
<ResizeableDataTable
102109
data={data}
103-
columns={columns}
104-
settings={{...TABLE_SETTINGS, ...props.settings}}
110+
columns={preparedColumns}
111+
settings={settings}
105112
// prevent accessing row.id in case it is present but is not the PK (i.e. may repeat)
106113
rowKey={getRowIndex}
107114
visibleRowIndex={getVisibleRowIndex}
108115
wrapperClassName={b('table-wrapper')}
109-
{...restProps}
110116
/>
111117
);
112118
};

src/containers/Tenant/Query/QueryEditor/QueryEditor.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import {
4040
} from '../../../../utils/hooks';
4141
import {useChangedQuerySettings} from '../../../../utils/hooks/useChangedQuerySettings';
4242
import {useLastQueryExecutionSettings} from '../../../../utils/hooks/useLastQueryExecutionSettings';
43-
import {QUERY_ACTIONS} from '../../../../utils/query';
43+
import {DEFAULT_QUERY_SETTINGS, QUERY_ACTIONS} from '../../../../utils/query';
4444
import type {InitialPaneState} from '../../utils/paneVisibilityToggleHelpers';
4545
import {
4646
PaneVisibilityActionTypes,
@@ -101,6 +101,16 @@ export default function QueryEditor(props: QueryEditorProps) {
101101

102102
const runningQueryRef = React.useRef<{abort: VoidFunction} | null>(null);
103103

104+
const tableSettings = React.useMemo(() => {
105+
return isStreamingEnabled
106+
? {
107+
displayIndices: {
108+
maxIndex: (querySettings.limitRows || DEFAULT_QUERY_SETTINGS.limitRows) + 1,
109+
},
110+
}
111+
: undefined;
112+
}, [isStreamingEnabled, querySettings.limitRows]);
113+
104114
React.useEffect(() => {
105115
if (savedPath !== tenantName) {
106116
dispatch(setTenantPath(tenantName));
@@ -266,11 +276,7 @@ export default function QueryEditor(props: QueryEditorProps) {
266276
showPreview={showPreview}
267277
queryText={lastExecutedQueryText}
268278
onCancelRunningQuery={handleCancelRunningQuery}
269-
tableSettings={
270-
isStreamingEnabled && querySettings.limitRows
271-
? {displayIndices: {maxIndex: querySettings.limitRows}}
272-
: undefined
273-
}
279+
tableSettings={tableSettings}
274280
/>
275281
</div>
276282
</SplitPane>

0 commit comments

Comments
 (0)