Skip to content

Commit c9ac514

Browse files
committed
perf(SchemaTree): batch preloaded data dispatch
1 parent 5d368fe commit c9ac514

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

src/containers/Tenant/Schema/SchemaTree/SchemaTree.tsx

+11-7
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import {useDispatch} from 'react-redux';
33

44
import {NavigationTree} from 'ydb-ui-components';
55

6-
import {setCurrentSchemaPath, getSchema, preloadSchema} from '../../../../store/reducers/schema';
6+
import {setCurrentSchemaPath, getSchema, preloadSchemas} from '../../../../store/reducers/schema';
77
import {getDescribe} from '../../../../store/reducers/describe';
88
import {getSchemaAcl} from '../../../../store/reducers/schemaAcl';
9-
import type {EPathType} from '../../../../types/api/schema';
9+
import type {EPathType, TEvDescribeSchemeResult} from '../../../../types/api/schema';
1010

1111
import {mapPathTypeToNavigationTreeType} from '../../utils/schema';
1212
import {getActions} from '../../utils/schemaActions';
@@ -29,15 +29,15 @@ export function SchemaTree(props: SchemaTreeProps) {
2929
.then((data) => {
3030
const {PathDescription: {Children = []} = {}} = data;
3131

32-
dispatch(preloadSchema(path, data));
32+
const preloadedData: Record<string, TEvDescribeSchemeResult> = {
33+
[path]: data
34+
};
3335

34-
return Children.map((childData) => {
36+
const childItems = Children.map((childData) => {
3537
const {Name = '', PathType, PathSubType} = childData;
3638

3739
// not full data, but it contains PathType, which ensures seamless switch between nodes
38-
dispatch(
39-
preloadSchema(`${path}/${Name}`, {PathDescription: {Self: childData}}),
40-
);
40+
preloadedData[`${path}/${Name}`] = {PathDescription: {Self: childData}};
4141

4242
return {
4343
name: Name,
@@ -47,6 +47,10 @@ export function SchemaTree(props: SchemaTreeProps) {
4747
expandable: true,
4848
};
4949
});
50+
51+
dispatch(preloadSchemas(preloadedData));
52+
53+
return childItems;
5054
});
5155

5256
const handleActivePathUpdate = (activePath: string) => {

src/store/reducers/schema.js

+8-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {createRequestActionTypes, createApiRequest} from '../utils';
22
import '../../services/api';
33

44
const FETCH_SCHEMA = createRequestActionTypes('schema', 'FETCH_SCHEMA');
5-
const PRELOAD_SCHEMA = 'schema/PRELOAD_SCHEMA';
5+
const PRELOAD_SCHEMAS = 'schema/PRELOAD_SCHEMAS';
66
const SET_SCHEMA = 'schema/SET_SCHEMA';
77
const SET_SHOW_PREVIEW = 'schema/SET_SHOW_PREVIEW';
88
const ENABLE_AUTOREFRESH = 'schema/ENABLE_AUTOREFRESH';
@@ -54,16 +54,13 @@ const schema = (state = initialState, action) => {
5454
loading: false,
5555
};
5656
}
57-
case PRELOAD_SCHEMA: {
58-
if (state.data[action.path]) {
59-
return state;
60-
}
61-
57+
case PRELOAD_SCHEMAS: {
6258
return {
6359
...state,
6460
data: {
61+
// we don't want to overwrite existing paths
62+
...action.data,
6563
...state.data,
66-
[action.path]: action.data,
6764
},
6865
};
6966
}
@@ -133,11 +130,11 @@ export function setShowPreview(value) {
133130
};
134131
}
135132

136-
// only stores the passed data if the path doesn't exist yet
137-
export function preloadSchema(path, data) {
133+
// only stores data for paths that are not in the store yet
134+
// existing paths are ignored
135+
export function preloadSchemas(data) {
138136
return {
139-
type: PRELOAD_SCHEMA,
140-
path,
137+
type: PRELOAD_SCHEMAS,
141138
data,
142139
};
143140
}

0 commit comments

Comments
 (0)