Skip to content

Commit 6106eca

Browse files
authored
refactor: improve /describe requests for schema objects (#1353)
1 parent 960e97f commit 6106eca

File tree

11 files changed

+98
-59
lines changed

11 files changed

+98
-59
lines changed

src/containers/Tenant/Diagnostics/Describe/Describe.tsx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import {shallowEqual} from 'react-redux';
55

66
import {ResponseError} from '../../../../components/Errors/ResponseError';
77
import {Loader} from '../../../../components/Loader';
8-
import {describeApi} from '../../../../store/reducers/describe';
8+
import {overviewApi} from '../../../../store/reducers/overview/overview';
99
import {selectSchemaMergedChildrenPaths} from '../../../../store/reducers/schema/schema';
1010
import type {EPathType} from '../../../../types/api/schema';
11+
import type {IDescribeData} from '../../../../types/store/describe';
1112
import {cn} from '../../../../utils/cn';
1213
import {useAutoRefreshInterval, useTypedSelector} from '../../../../utils/hooks';
1314
import {isEntityWithMergedImplementation} from '../../utils/schema';
@@ -25,6 +26,8 @@ interface IDescribeProps {
2526
type?: EPathType;
2627
}
2728

29+
const emptyObject: IDescribeData = {};
30+
2831
const Describe = ({path, database, type}: IDescribeProps) => {
2932
const [autoRefreshInterval] = useAutoRefreshInterval();
3033

@@ -41,14 +44,29 @@ const Describe = ({path, database, type}: IDescribeProps) => {
4144
} else if (mergedChildrenPaths) {
4245
paths = [path, ...mergedChildrenPaths];
4346
}
44-
const {currentData, isFetching, error} = describeApi.useGetDescribeQuery(
47+
const {currentDescribe, currentData, isFetching, error} = overviewApi.useGetOverviewQuery(
4548
paths.length ? {paths, database} : skipToken,
4649
{
4750
pollingInterval: autoRefreshInterval,
51+
selectFromResult: (props) => {
52+
const {currentData} = props;
53+
if (!currentData) {
54+
return {currentDescribe: emptyObject, ...props};
55+
}
56+
57+
const mergedData = [currentData.data, ...currentData.additionalData];
58+
59+
const data = mergedData.reduce<IDescribeData>((acc, item) => {
60+
if (item?.Path) {
61+
acc[item.Path] = item;
62+
}
63+
return acc;
64+
}, {});
65+
return {currentDescribe: data, ...props};
66+
},
4867
},
4968
);
5069
const loading = isFetching && currentData === undefined;
51-
const currentDescribe = currentData;
5270

5371
let preparedDescribeData: Object | undefined;
5472
if (currentDescribe) {

src/containers/Tenant/Diagnostics/HotKeys/HotKeys.tsx

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import {Button, Card, Icon} from '@gravity-ui/uikit';
88
import {ResponseError} from '../../../../components/Errors/ResponseError';
99
import {ResizeableDataTable} from '../../../../components/ResizeableDataTable/ResizeableDataTable';
1010
import {hotKeysApi} from '../../../../store/reducers/hotKeys/hotKeys';
11-
import {useGetSchemaQuery} from '../../../../store/reducers/schema/schema';
11+
import {overviewApi} from '../../../../store/reducers/overview/overview';
1212
import type {HotKey} from '../../../../types/api/hotkeys';
1313
import {cn} from '../../../../utils/cn';
1414
import {DEFAULT_TABLE_SETTINGS, IS_HOTKEYS_HELP_HIDDEN_KEY} from '../../../../utils/constants';
15-
import {useSetting} from '../../../../utils/hooks';
15+
import {useAutoRefreshInterval, useSetting} from '../../../../utils/hooks';
1616

1717
import i18n from './i18n';
1818

@@ -61,9 +61,17 @@ interface HotKeysProps {
6161
export function HotKeys({path, database}: HotKeysProps) {
6262
const {currentData: data, isFetching, error} = hotKeysApi.useGetHotKeysQuery({path, database});
6363
const loading = isFetching && data === undefined;
64-
65-
const {data: schemaData, isLoading: schemaLoading} = useGetSchemaQuery({path, database});
66-
64+
const [autoRefreshInterval] = useAutoRefreshInterval();
65+
const {currentData, isLoading: schemaLoading} = overviewApi.useGetOverviewQuery(
66+
{
67+
paths: [path],
68+
database,
69+
},
70+
{
71+
pollingInterval: autoRefreshInterval,
72+
},
73+
);
74+
const {data: schemaData} = currentData ?? {};
6775
const keyColumnsIds = schemaData?.PathDescription?.Table?.KeyColumnNames;
6876

6977
const tableColumns = React.useMemo(() => {

src/containers/Tenant/Diagnostics/Overview/Overview.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ import {ResponseError} from '../../../../components/Errors/ResponseError';
77
import {TableIndexInfo} from '../../../../components/InfoViewer/schemaInfo';
88
import {Loader} from '../../../../components/Loader';
99
import {overviewApi} from '../../../../store/reducers/overview/overview';
10-
import {
11-
selectSchemaMergedChildrenPaths,
12-
useGetSchemaQuery,
13-
} from '../../../../store/reducers/schema/schema';
10+
import {selectSchemaMergedChildrenPaths} from '../../../../store/reducers/schema/schema';
1411
import {EPathType} from '../../../../types/api/schema';
1512
import {useAutoRefreshInterval, useTypedSelector} from '../../../../utils/hooks';
1613
import {ExternalDataSourceInfo} from '../../Info/ExternalDataSource/ExternalDataSource';
@@ -57,8 +54,6 @@ function Overview({type, path, database}: OverviewProps) {
5754
const overviewLoading = isFetching && currentData === undefined;
5855
const {data: rawData, additionalData} = currentData || {};
5956

60-
const {error: schemaError} = useGetSchemaQuery({path, database});
61-
6257
const entityLoading = overviewLoading;
6358
const entityNotReady = isEntityWithMergedImpl && !mergedChildrenPaths;
6459

@@ -101,7 +96,6 @@ function Overview({type, path, database}: OverviewProps) {
10196

10297
return (
10398
<React.Fragment>
104-
{schemaError ? <ResponseError error={schemaError} /> : null}
10599
{overviewError ? <ResponseError error={overviewError} /> : null}
106100
{overviewError && !rawData ? null : renderContent()}
107101
</React.Fragment>

src/containers/Tenant/Diagnostics/TenantOverview/TenantOverview.tsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Loader} from '@gravity-ui/uikit';
22

33
import {EntityStatus} from '../../../../components/EntityStatus/EntityStatus';
4-
import {useGetSchemaQuery} from '../../../../store/reducers/schema/schema';
4+
import {overviewApi} from '../../../../store/reducers/overview/overview';
55
import {TENANT_METRICS_TABS_IDS} from '../../../../store/reducers/tenant/constants';
66
import {tenantApi} from '../../../../store/reducers/tenant/tenant';
77
import {calculateTenantMetrics} from '../../../../store/reducers/tenants/utils';
@@ -44,9 +44,17 @@ export function TenantOverview({
4444
const {Name, Type, Overall} = tenant || {};
4545

4646
const tenantType = mapDatabaseTypeToDBName(Type);
47-
4847
// FIXME: remove after correct data is added to tenantInfo
49-
const {data: tenantSchemaData} = useGetSchemaQuery({path: tenantName, database: tenantName});
48+
const {currentData} = overviewApi.useGetOverviewQuery(
49+
{
50+
paths: [tenantName],
51+
database: tenantName,
52+
},
53+
{
54+
pollingInterval: autoRefreshInterval,
55+
},
56+
);
57+
const {data: tenantSchemaData} = currentData ?? {};
5058
const {Tables, Topics} =
5159
tenantSchemaData?.PathDescription?.DomainDescription?.DiskSpaceUsage || {};
5260

src/containers/Tenant/ObjectSummary/ObjectSummary.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import type {InfoViewerItem} from '../../../components/InfoViewer/InfoViewer';
1414
import {LinkWithIcon} from '../../../components/LinkWithIcon/LinkWithIcon';
1515
import SplitPane from '../../../components/SplitPane';
1616
import routes, {createExternalUILink, createHref} from '../../../routes';
17-
import {useGetSchemaQuery} from '../../../store/reducers/schema/schema';
17+
import {overviewApi} from '../../../store/reducers/overview/overview';
1818
import {TENANT_SUMMARY_TABS_IDS} from '../../../store/reducers/tenant/constants';
1919
import {setSummaryTab} from '../../../store/reducers/tenant/tenant';
2020
import {EPathSubType, EPathType} from '../../../types/api/schema';
@@ -27,7 +27,7 @@ import {
2727
formatNumber,
2828
formatSecondsToHours,
2929
} from '../../../utils/dataFormatters/dataFormatters';
30-
import {useTypedDispatch, useTypedSelector} from '../../../utils/hooks';
30+
import {useAutoRefreshInterval, useTypedDispatch, useTypedSelector} from '../../../utils/hooks';
3131
import {Acl} from '../Acl/Acl';
3232
import {EntityTitle} from '../EntityTitle/EntityTitle';
3333
import {SchemaViewer} from '../Schema/SchemaViewer/SchemaViewer';
@@ -77,6 +77,7 @@ export function ObjectSummary({
7777
onExpandSummary,
7878
isCollapsed,
7979
}: ObjectSummaryProps) {
80+
const [autoRefreshInterval] = useAutoRefreshInterval();
8081
const dispatch = useTypedDispatch();
8182
const [, setCurrentPath] = useQueryParam('schema', StringParam);
8283
const [commonInfoVisibilityState, dispatchCommonInfoVisibilityState] = React.useReducer(
@@ -94,7 +95,16 @@ export function ObjectSummary({
9495
ignoreQueryPrefix: true,
9596
});
9697

97-
const {data: currentObjectData} = useGetSchemaQuery({path, database: tenantName});
98+
const {currentData} = overviewApi.useGetOverviewQuery(
99+
{
100+
paths: [path],
101+
database: tenantName,
102+
},
103+
{
104+
pollingInterval: autoRefreshInterval,
105+
},
106+
);
107+
const {data: currentObjectData} = currentData ?? {};
98108
const currentSchemaData = currentObjectData?.PathDescription?.Self;
99109

100110
React.useEffect(() => {

src/containers/Tenant/Schema/SchemaViewer/SchemaViewer.tsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import {skipToken} from '@reduxjs/toolkit/query';
44

55
import {ResizeableDataTable} from '../../../../components/ResizeableDataTable/ResizeableDataTable';
66
import {TableSkeleton} from '../../../../components/TableSkeleton/TableSkeleton';
7-
import {useGetSchemaQuery} from '../../../../store/reducers/schema/schema';
7+
import {overviewApi} from '../../../../store/reducers/overview/overview';
88
import {viewSchemaApi} from '../../../../store/reducers/viewSchema/viewSchema';
99
import type {EPathType} from '../../../../types/api/schema';
1010
import {DEFAULT_TABLE_SETTINGS} from '../../../../utils/constants';
11+
import {useAutoRefreshInterval} from '../../../../utils/hooks';
1112
import {
1213
isColumnEntityType,
1314
isExternalTableType,
@@ -36,7 +37,18 @@ interface SchemaViewerProps {
3637
}
3738

3839
export const SchemaViewer = ({type, path, tenantName, extended = false}: SchemaViewerProps) => {
39-
const {data: schemaData, isLoading: loading} = useGetSchemaQuery({path, database: tenantName});
40+
const [autoRefreshInterval] = useAutoRefreshInterval();
41+
const {currentData, isLoading: loading} = overviewApi.useGetOverviewQuery(
42+
{
43+
paths: [path],
44+
database: tenantName,
45+
},
46+
{
47+
pollingInterval: autoRefreshInterval,
48+
},
49+
);
50+
51+
const {data: schemaData} = currentData ?? {};
4052

4153
const viewSchemaRequestParams = isViewType(type) ? {path, database: tenantName} : skipToken;
4254

src/containers/Tenant/Schema/SchemaViewer/prepareData.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {
88
TTableDescription,
99
} from '../../../../types/api/schema';
1010
import {EColumnCodec} from '../../../../types/api/schema';
11+
import type {Nullable} from '../../../../utils/typecheckers';
1112
import {isColumnEntityType, isExternalTableType, isRowTableType} from '../../utils/schema';
1213

1314
import type {SchemaData} from './types';
@@ -123,7 +124,7 @@ function prepareColumnTableSchema(data: TColumnTableDescription = {}): SchemaDat
123124

124125
export function prepareSchemaData(
125126
type?: EPathType,
126-
schema?: TEvDescribeSchemeResult,
127+
schema?: Nullable<TEvDescribeSchemeResult>,
127128
): SchemaData[] {
128129
const {Table, ColumnTableDescription, ExternalTableDescription} = schema?.PathDescription || {};
129130

src/containers/Tenant/Tenant.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import {PageError, isAccessError} from '../../components/Errors/PageError/PageEr
77
import {LoaderWrapper} from '../../components/LoaderWrapper/LoaderWrapper';
88
import SplitPane from '../../components/SplitPane';
99
import {setHeaderBreadcrumbs} from '../../store/reducers/header/header';
10-
import {useGetSchemaQuery} from '../../store/reducers/schema/schema';
10+
import {overviewApi} from '../../store/reducers/overview/overview';
1111
import type {AdditionalNodesProps, AdditionalTenantsProps} from '../../types/additionalProps';
1212
import {cn} from '../../utils/cn';
1313
import {DEFAULT_IS_TENANT_SUMMARY_COLLAPSED, DEFAULT_SIZE_TENANT_KEY} from '../../utils/constants';
14-
import {useTypedDispatch} from '../../utils/hooks';
14+
import {useAutoRefreshInterval, useTypedDispatch} from '../../utils/hooks';
1515

1616
import ObjectGeneral from './ObjectGeneral/ObjectGeneral';
1717
import {ObjectSummary} from './ObjectSummary/ObjectSummary';
@@ -41,6 +41,7 @@ interface TenantProps {
4141
}
4242

4343
export function Tenant(props: TenantProps) {
44+
const [autoRefreshInterval] = useAutoRefreshInterval();
4445
const [summaryVisibilityState, dispatchSummaryVisibilityAction] = React.useReducer(
4546
paneVisibilityToggleReducerCreator(DEFAULT_IS_TENANT_SUMMARY_COLLAPSED),
4647
undefined,
@@ -74,7 +75,13 @@ export function Tenant(props: TenantProps) {
7475

7576
const path = schema ?? tenantName;
7677

77-
const {data: currentItem, error, isLoading} = useGetSchemaQuery({path, database: tenantName});
78+
const {currentData, error, isLoading} = overviewApi.useGetOverviewQuery(
79+
{paths: [path], database: tenantName},
80+
{
81+
pollingInterval: autoRefreshInterval,
82+
},
83+
);
84+
const {data: currentItem} = currentData ?? {};
7885
const {PathType: currentPathType, PathSubType: currentPathSubType} =
7986
currentItem?.PathDescription?.Self || {};
8087

src/services/api.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,9 @@ export class YdbEmbeddedAPI extends AxiosWrapper {
366366
enums: true,
367367
backup: false,
368368
private: true,
369-
partition_config: true,
370-
partition_stats: true,
371-
partitioning_info: true,
369+
partition_config: false,
370+
partition_stats: false,
371+
partitioning_info: false,
372372
subs: 1,
373373
},
374374
{concurrentId, requestConfig: {signal}},

src/store/reducers/describe.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)