Skip to content

Commit 2efd40c

Browse files
committed
fix: review fixes
1 parent 9e3b29d commit 2efd40c

File tree

6 files changed

+22
-46
lines changed

6 files changed

+22
-46
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import {schemaApi} from '../../../../store/reducers/schema/schema';
1010
import type {GetTableSchemaDataParams} from '../../../../store/reducers/tableSchemaData';
1111
import {useGetTableSchemaDataMutation} from '../../../../store/reducers/tableSchemaData';
1212
import type {EPathType, TEvDescribeSchemeResult} from '../../../../types/api/schema';
13+
import {wait} from '../../../../utils';
14+
import {SECOND_IN_MS} from '../../../../utils/constants';
1315
import {useQueryExecutionSettings, useTypedDispatch} from '../../../../utils/hooks';
1416
import {getSchemaControls} from '../../utils/controls';
1517
import {isChildlessPathType, mapPathTypeToNavigationTreeType} from '../../utils/schema';
@@ -24,6 +26,8 @@ interface SchemaTreeProps {
2426
onActivePathUpdate: (path: string) => void;
2527
}
2628

29+
const TABLE_SCHEMA_TIMEOUT = SECOND_IN_MS * 2;
30+
2731
export function SchemaTree(props: SchemaTreeProps) {
2832
const createDirectoryFeatureAvailable = useCreateDirectoryFeatureAvailable();
2933
const {rootPath, rootName, rootType, currentPath, onActivePathUpdate} = props;
@@ -33,7 +37,10 @@ export function SchemaTree(props: SchemaTreeProps) {
3337
const getTableSchemaDataPromise = React.useCallback(
3438
async (args: GetTableSchemaDataParams) => {
3539
try {
36-
const result = await getTableSchemaDataMutation(args).unwrap();
40+
const result = await Promise.race([
41+
getTableSchemaDataMutation(args).unwrap(),
42+
wait<undefined>(TABLE_SCHEMA_TIMEOUT),
43+
]);
3744
return result;
3845
} catch (e) {
3946
return undefined;

src/services/api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ export class YdbEmbeddedAPI extends AxiosWrapper {
374374
);
375375
}
376376
getDescribe(
377-
{path, database, timeout}: {path: string; database: string; timeout?: Timeout},
377+
{path, database}: {path: string; database: string},
378378
{concurrentId, signal}: AxiosOptions = {},
379379
) {
380380
return this.get<Nullable<TEvDescribeSchemeResult>>(
@@ -386,7 +386,7 @@ export class YdbEmbeddedAPI extends AxiosWrapper {
386386
partition_stats: true,
387387
subs: 0,
388388
},
389-
{concurrentId: concurrentId || `getDescribe|${path}`, requestConfig: {signal}, timeout},
389+
{concurrentId: concurrentId || `getDescribe|${path}`, requestConfig: {signal}},
390390
);
391391
}
392392
getSchemaAcl(

src/store/reducers/overview/overview.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
1-
import type {Timeout} from '../../../types/api/query';
21
import {api} from '../api';
32

43
export const overviewApi = api.injectEndpoints({
54
endpoints: (build) => ({
65
getOverview: build.query({
7-
queryFn: async (
8-
{
9-
paths,
10-
database,
11-
timeout,
12-
concurrentId,
13-
}: {paths: string[]; database: string; timeout?: Timeout; concurrentId?: string},
14-
{signal},
15-
) => {
6+
queryFn: async ({paths, database}: {paths: string[]; database: string}, {signal}) => {
167
try {
178
const [data, ...additionalData] = await Promise.all(
189
paths.map((p) =>
1910
window.api.getDescribe(
2011
{
2112
path: p,
2213
database,
23-
timeout,
2414
},
25-
{signal, concurrentId},
15+
{signal},
2616
),
2717
),
2818
);

src/store/reducers/tableSchemaData.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,16 @@ export interface GetTableSchemaDataParams {
1717
type: EPathType;
1818
}
1919

20-
const TABLE_SCHEMA_TIMEOUT = 1000;
21-
22-
const getTableSchemaDataConcurrentId = 'getTableSchemaData';
23-
2420
export const tableSchemeDataApi = api.injectEndpoints({
2521
endpoints: (build) => ({
2622
getTableSchemaData: build.mutation<SchemaData[], GetTableSchemaDataParams>({
2723
queryFn: async ({path, tenantName, type}, {dispatch}) => {
2824
try {
29-
const schemaData = await dispatch(
30-
overviewApi.endpoints.getOverview.initiate({
31-
paths: [path],
32-
database: tenantName,
33-
timeout: TABLE_SCHEMA_TIMEOUT,
34-
concurrentId: getTableSchemaDataConcurrentId + 'getOverview',
35-
}),
36-
);
37-
3825
if (isViewType(type)) {
3926
const response = await dispatch(
4027
viewSchemaApi.endpoints.getViewSchema.initiate({
4128
database: tenantName,
4229
path,
43-
timeout: TABLE_SCHEMA_TIMEOUT,
44-
concurrentId: getTableSchemaDataConcurrentId + 'getViewSchema',
4530
}),
4631
);
4732

@@ -53,6 +38,12 @@ export const tableSchemeDataApi = api.injectEndpoints({
5338
return {data: result};
5439
}
5540

41+
const schemaData = await dispatch(
42+
overviewApi.endpoints.getOverview.initiate({
43+
paths: [path],
44+
database: tenantName,
45+
}),
46+
);
5647
const result = prepareSchemaData(type, schemaData.data?.data);
5748

5849
return {data: result};

src/store/reducers/viewSchema/viewSchema.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type {Timeout} from '../../../types/api/query';
21
import {isQueryErrorResponse} from '../../../utils/query';
32
import {api} from '../api';
43

@@ -9,26 +8,15 @@ export function createViewSchemaQuery(path: string) {
98
export const viewSchemaApi = api.injectEndpoints({
109
endpoints: (build) => ({
1110
getViewSchema: build.query({
12-
queryFn: async ({
13-
database,
14-
path,
15-
timeout,
16-
concurrentId,
17-
}: {
18-
database: string;
19-
path: string;
20-
timeout?: Timeout;
21-
concurrentId?: string;
22-
}) => {
11+
queryFn: async ({database, path}: {database: string; path: string}) => {
2312
try {
2413
const response = await window.api.sendQuery(
2514
{
2615
query: createViewSchemaQuery(path),
2716
database,
2817
action: 'execute-scan',
29-
timeout,
3018
},
31-
{withRetries: true, concurrentId},
19+
{withRetries: true},
3220
);
3321

3422
if (isQueryErrorResponse(response)) {

src/utils/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export function valueIsDefined<T>(value: T | null | undefined): value is T {
66
return value !== null && value !== undefined;
77
}
88

9-
export async function wait(time: number) {
9+
export async function wait<T = unknown>(time: number, value?: T): Promise<T | undefined> {
1010
return new Promise((resolve) => {
11-
setTimeout(resolve, time);
11+
setTimeout(() => resolve(value), time);
1212
});
1313
}

0 commit comments

Comments
 (0)