Skip to content

Commit 105fd2c

Browse files
authoredMar 17, 2025
feat: query streaming only for queryService (#2015)
1 parent 577c9aa commit 105fd2c

File tree

3 files changed

+38
-28
lines changed

3 files changed

+38
-28
lines changed
 

‎src/containers/Tenant/Query/QueryEditor/QueryEditor.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import {
3939
} from '../../../../utils/hooks';
4040
import {useChangedQuerySettings} from '../../../../utils/hooks/useChangedQuerySettings';
4141
import {useLastQueryExecutionSettings} from '../../../../utils/hooks/useLastQueryExecutionSettings';
42-
import {DEFAULT_QUERY_SETTINGS, QUERY_ACTIONS} from '../../../../utils/query';
42+
import {DEFAULT_QUERY_SETTINGS, QUERY_ACTIONS, QUERY_MODES} from '../../../../utils/query';
4343
import type {InitialPaneState} from '../../utils/paneVisibilityToggleHelpers';
4444
import {
4545
PaneVisibilityActionTypes,
@@ -93,7 +93,11 @@ export default function QueryEditor(props: QueryEditorProps) {
9393
);
9494
const [lastExecutedQueryText, setLastExecutedQueryText] = React.useState<string>('');
9595
const [isQueryStreamingEnabled] = useSetting<boolean>(ENABLE_QUERY_STREAMING);
96-
const isStreamingEnabled = useStreamingAvailable() && isQueryStreamingEnabled;
96+
97+
const isStreamingEnabled =
98+
useStreamingAvailable() &&
99+
isQueryStreamingEnabled &&
100+
querySettings.queryMode === QUERY_MODES.query;
97101

98102
const [sendQuery] = queryApi.useUseSendQueryMutation();
99103
const [streamQuery] = queryApi.useUseStreamQueryMutation();

‎src/containers/Tenant/Query/QueryEditorControls/QueryEditorControls.tsx

+21-23
Original file line numberDiff line numberDiff line change
@@ -90,30 +90,28 @@ export const QueryEditorControls = ({
9090
const [cancelQueryError, setCancelQueryError] = React.useState<boolean>(false);
9191

9292
const onStopButtonClick = React.useCallback(async () => {
93-
if (queryId) {
94-
try {
95-
if (isStreamingEnabled) {
96-
queryManagerInstance.abortQuery();
97-
} else if (queryId) {
98-
await sendCancelQuery({queryId, database: tenantName}).unwrap();
99-
}
100-
} catch {
101-
createToast({
102-
name: 'stop-error',
103-
title: '',
104-
content: i18n('toaster.stop-error'),
105-
type: 'error',
106-
autoHiding: STOP_AUTO_HIDE_TIMEOUT,
107-
});
108-
setCancelQueryError(true);
109-
110-
if (cancelErrorAnimationRef.current) {
111-
window.clearTimeout(cancelErrorAnimationRef.current);
112-
}
113-
cancelErrorAnimationRef.current = window.setTimeout(() => {
114-
setCancelQueryError(false);
115-
}, CANCEL_ERROR_ANIMATION_DURATION);
93+
try {
94+
if (isStreamingEnabled) {
95+
queryManagerInstance.abortQuery();
96+
} else if (queryId) {
97+
await sendCancelQuery({queryId, database: tenantName}).unwrap();
11698
}
99+
} catch {
100+
createToast({
101+
name: 'stop-error',
102+
title: '',
103+
content: i18n('toaster.stop-error'),
104+
type: 'error',
105+
autoHiding: STOP_AUTO_HIDE_TIMEOUT,
106+
});
107+
setCancelQueryError(true);
108+
109+
if (cancelErrorAnimationRef.current) {
110+
window.clearTimeout(cancelErrorAnimationRef.current);
111+
}
112+
cancelErrorAnimationRef.current = window.setTimeout(() => {
113+
setCancelQueryError(false);
114+
}, CANCEL_ERROR_ANIMATION_DURATION);
117115
}
118116
}, [isStreamingEnabled, queryId, sendCancelQuery, tenantName]);
119117

‎src/containers/Tenant/Query/QueryResult/components/Graph/Graph.tsx

+11-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import React from 'react';
2+
3+
import type {Data} from '@gravity-ui/paranoid';
4+
15
import {YDBGraph} from '../../../../../../components/Graph/Graph';
26
import type {PreparedPlan} from '../../../../../../store/reducers/query/types';
37
import {cn} from '../../../../../../utils/cn';
@@ -13,18 +17,22 @@ interface GraphProps {
1317
theme?: string;
1418
}
1519

20+
function isValidGraphData(data: Partial<Data>): data is Data {
21+
return Boolean(data.links && data.nodes && data.nodes.length);
22+
}
23+
1624
export function Graph({explain = {}, theme}: GraphProps) {
1725
const {links, nodes} = explain;
1826

19-
const isEnoughDataForGraph = links && nodes && nodes.length;
27+
const data = React.useMemo(() => ({links, nodes}), [links, nodes]);
2028

21-
if (!isEnoughDataForGraph) {
29+
if (!isValidGraphData(data)) {
2230
return <StubMessage message={i18n('description.graph-is-not-supported')} />;
2331
}
2432

2533
return (
2634
<div className={b('canvas-container')}>
27-
<YDBGraph key={theme} data={{links, nodes}} />
35+
<YDBGraph key={theme} data={data} />
2836
</div>
2937
);
3038
}

0 commit comments

Comments
 (0)