Skip to content

Commit d8ffe1a

Browse files
authored
refactor: replace SELECT * with explicit column list and SQL alias
- Select only the 12 columns actually used by the table and drawer - Alias `Query as QueryText` directly in SQL, eliminating the need for the normalizeQueryResult helper - Remove normalizeQueryToQueryText and normalizeQueryResult functions and their tests (no longer needed) Agent-Logs-Url: https://github.com/ydb-platform/ydb-embedded-ui/sessions/bceebd7e-4ca5-4e85-a499-f6f4cb44eb61
1 parent d917a46 commit d8ffe1a

3 files changed

Lines changed: 16 additions & 207 deletions

File tree

src/store/reducers/executeTopQueries/__test__/utils.test.ts

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

src/store/reducers/executeTopQueries/executeTopQueries.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {api} from '../api';
1010

1111
import {TOP_QUERIES_TABLES} from './constants';
1212
import type {TimeFrame, TopQueriesFilters} from './types';
13-
import {getFiltersConditions, normalizeQueryResult} from './utils';
13+
import {getFiltersConditions} from './utils';
1414

1515
const initialState: TopQueriesFilters = {};
1616

@@ -87,7 +87,19 @@ function getRunningQueriesText(
8787
const orderBy = prepareOrderByFromTableSort(sortOrder);
8888

8989
return `${QUERY_TECHNICAL_MARK}
90-
SELECT *
90+
SELECT
91+
Query as QueryText,
92+
UserSID,
93+
QueryStartAt,
94+
ApplicationName,
95+
WmPoolId,
96+
WmState,
97+
WmEnterTime,
98+
WmExitTime,
99+
ClientAddress,
100+
ClientPID,
101+
ClientUserAgent,
102+
ClientSdkBuildInfo
91103
FROM \`.sys/query_sessions\`
92104
WHERE ${filterConditions || 'true'} AND Query NOT LIKE '%${QUERY_TECHNICAL_MARK}%'
93105
AND QueryStartAt is not null ${orderBy}
@@ -184,9 +196,9 @@ export const topQueriesApi = api.injectEndpoints({
184196
throw response;
185197
}
186198

187-
const parsed = parseQueryAPIResponse(response);
199+
const data = parseQueryAPIResponse(response);
188200

189-
return {data: normalizeQueryResult(parsed)};
201+
return {data};
190202
} catch (error) {
191203
return {error};
192204
}

src/store/reducers/executeTopQueries/utils.ts

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import {dateTimeParse} from '@gravity-ui/date-utils';
22

3-
import type {KeyValueRow} from '../../../types/api/query';
4-
import type {IQueryResult} from '../../../types/store/query';
5-
63
import type {TopQueriesFilters} from './types';
74

85
const endTimeColumn = 'EndTime';
@@ -47,33 +44,3 @@ export function getFiltersConditions(tableName: string, filters?: TopQueriesFilt
4744

4845
return conditions.join(' AND ');
4946
}
50-
51-
/**
52-
* Remap 'Query' → 'QueryText' in each row, dropping the original key.
53-
* SELECT * returns 'Query', but the UI uses 'QueryText'.
54-
*/
55-
function normalizeQueryToQueryText(row: KeyValueRow): KeyValueRow {
56-
if (row.Query !== undefined && !row.QueryText) {
57-
const {Query, ...rest} = row;
58-
return {...rest, QueryText: Query};
59-
}
60-
return row;
61-
}
62-
63-
/** Normalize a parsed query response so the first result set uses 'QueryText'. */
64-
export function normalizeQueryResult(parsed: IQueryResult): IQueryResult {
65-
const rows = parsed.resultSets?.[0]?.result;
66-
67-
if (!rows) {
68-
return parsed;
69-
}
70-
71-
return {
72-
...parsed,
73-
resultSets: parsed.resultSets!.map((resultSet, index) =>
74-
index === 0 && resultSet.result
75-
? {...resultSet, result: resultSet.result.map(normalizeQueryToQueryText)}
76-
: resultSet,
77-
),
78-
};
79-
}

0 commit comments

Comments
 (0)