Skip to content

Commit

Permalink
fix(sqllab): perf regression on apache#21532 refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
justinpark committed Sep 29, 2022
1 parent 5ea9249 commit 6986c32
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jest.mock('src/components/AsyncAceEditor', () => ({
const setup = (queryEditor: QueryEditor, store?: Store) =>
render(
<AceEditorWrapper
queryEditor={queryEditor}
queryEditorId={queryEditor.id}
height="100px"
hotkeys={[]}
database={{}}
Expand Down
16 changes: 11 additions & 5 deletions superset-frontend/src/SqlLab/components/AceEditorWrapper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License.
*/
import React, { useState, useEffect, useRef } from 'react';
import { useDispatch } from 'react-redux';
import { useDispatch, useSelector } from 'react-redux';
import { usePrevious } from 'src/hooks/usePrevious';
import { areArraysShallowEqual } from 'src/reduxUtils';
import sqlKeywords from 'src/SqlLab/utils/sqlKeywords';
Expand All @@ -37,7 +37,7 @@ import {
AceCompleterKeyword,
FullSQLEditor as AceEditor,
} from 'src/components/AsyncAceEditor';
import { QueryEditor } from 'src/SqlLab/types';
import { QueryEditor, SqlLabRootState } from 'src/SqlLab/types';

type HotKey = {
key: string;
Expand All @@ -50,7 +50,7 @@ type AceEditorWrapperProps = {
autocomplete: boolean;
onBlur: (sql: string) => void;
onChange: (sql: string) => void;
queryEditor: QueryEditor;
queryEditorId: string;
database: any;
extendedTables?: Array<{ name: string; columns: any[] }>;
height: string;
Expand All @@ -61,15 +61,21 @@ const AceEditorWrapper = ({
autocomplete,
onBlur = () => {},
onChange = () => {},
queryEditor,
queryEditorId,
database,
extendedTables = [],
height,
hotkeys,
}: AceEditorWrapperProps) => {
const dispatch = useDispatch();

const { sql: currentSql } = queryEditor;
const queryEditor = useSelector<SqlLabRootState, Partial<QueryEditor>>(
({ sqlLab: { unsavedQueryEditor, queryEditors } }) => ({
...queryEditors.find(({ id }) => id === queryEditorId),
...(queryEditorId === unsavedQueryEditor.id && unsavedQueryEditor),
}),
);
const currentSql = queryEditor.sql ?? '';
const functionNames = queryEditor.functionNames ?? [];
const schemas = queryEditor.schemaOptions ?? [];
const tables = queryEditor.tableOptions ?? [];
Expand Down
15 changes: 5 additions & 10 deletions superset-frontend/src/SqlLab/components/SqlEditor/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -163,26 +163,21 @@ const SqlEditor = ({
const theme = useTheme();
const dispatch = useDispatch();

const { currentQueryEditor, database, latestQuery, hideLeftBar } =
useSelector(({ sqlLab: { unsavedQueryEditor, databases, queries } }) => {
const currentQueryEditor = {
...queryEditor,
...(queryEditor.id === unsavedQueryEditor.id && unsavedQueryEditor),
};

const { database, latestQuery, hideLeftBar } = useSelector(
({ sqlLab: { unsavedQueryEditor, databases, queries } }) => {
let { dbId, latestQueryId, hideLeftBar } = queryEditor;
if (unsavedQueryEditor.id === queryEditor.id) {
dbId = unsavedQueryEditor.dbId || dbId;
latestQueryId = unsavedQueryEditor.latestQueryId || latestQueryId;
hideLeftBar = unsavedQueryEditor.hideLeftBar || hideLeftBar;
}
return {
currentQueryEditor,
database: databases[dbId],
latestQuery: queries[latestQueryId],
hideLeftBar,
};
});
},
);

const queryEditors = useSelector(({ sqlLab }) => sqlLab.queryEditors);

Expand Down Expand Up @@ -616,7 +611,7 @@ const SqlEditor = ({
autocomplete={autocompleteEnabled}
onBlur={setQueryEditorAndSaveSql}
onChange={onSqlChanged}
queryEditor={currentQueryEditor}
queryEditorId={queryEditor.id}
database={database}
extendedTables={tables}
height={`${aceEditorHeight}px`}
Expand Down

0 comments on commit 6986c32

Please sign in to comment.