Skip to content

Commit

Permalink
fix(sqllab): rendering performance regression (apache#23653)
Browse files Browse the repository at this point in the history
  • Loading branch information
justinpark authored and sebastianliebscher committed Apr 28, 2023
1 parent a0baa25 commit 465b7f8
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import thunk from 'redux-thunk';
import configureStore from 'redux-mock-store';
import fetchMock from 'fetch-mock';
import {
SET_QUERY_EDITOR_SQL_DEBOUNCE_MS,
SQL_EDITOR_GUTTER_HEIGHT,
SQL_EDITOR_GUTTER_MARGIN,
SQL_TOOLBAR_HEIGHT,
Expand All @@ -43,8 +44,14 @@ import {

jest.mock('src/components/AsyncAceEditor', () => ({
...jest.requireActual('src/components/AsyncAceEditor'),
FullSQLEditor: props => (
<div data-test="react-ace">{JSON.stringify(props)}</div>
FullSQLEditor: ({ onChange, onBlur, value }) => (
<textarea
data-test="react-ace"
onChange={evt => onChange(evt.target.value)}
onBlur={onBlur}
>
{value}
</textarea>
),
}));
jest.mock('src/SqlLab/components/SqlEditorLeftBar', () => () => (
Expand Down Expand Up @@ -166,10 +173,8 @@ describe('SqlEditor', () => {
},
}),
);

expect(await findByTestId('react-ace')).toHaveTextContent(
JSON.stringify({ value: expectedSql }).slice(1, -1),
);
const editor = await findByTestId('react-ace');
expect(editor).toHaveValue(expectedSql);
});

it('render a SouthPane', async () => {
Expand All @@ -179,6 +184,28 @@ describe('SqlEditor', () => {
).toBeInTheDocument();
});

it('triggers setQueryEditorAndSaveSql with debounced call to avoid performance regression', async () => {
const { findByTestId } = setup(mockedProps, store);
const editor = await findByTestId('react-ace');
const sql = 'select *';
fireEvent.change(editor, { target: { value: sql } });
// Verify no immediate sql update triggered
expect(
store.getActions().filter(({ type }) => type === 'QUERY_EDITOR_SET_SQL'),
).toHaveLength(0);
await waitFor(
() =>
expect(
store
.getActions()
.filter(({ type }) => type === 'QUERY_EDITOR_SET_SQL'),
).toHaveLength(1),
{
timeout: SET_QUERY_EDITOR_SQL_DEBOUNCE_MS + 100,
},
);
});

it('runs query action with ctas false', async () => {
const expectedStore = mockStore({
...initialState,
Expand Down
2 changes: 0 additions & 2 deletions superset-frontend/src/SqlLab/components/SqlEditor/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import {
persistEditorHeight,
postStopQuery,
queryEditorSetAutorun,
queryEditorSetSql,
queryEditorSetAndSaveSql,
queryEditorSetTemplateParams,
runQueryFromSqlEditor,
Expand Down Expand Up @@ -456,7 +455,6 @@ const SqlEditor = ({
);

const onSqlChanged = sql => {
dispatch(queryEditorSetSql(queryEditor, sql));
setQueryEditorAndSaveSqlWithDebounce(sql);
// Request server-side validation of the query text
if (canValidateQuery()) {
Expand Down

0 comments on commit 465b7f8

Please sign in to comment.