Skip to content

feat: query streaming only for queryService #2015

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/containers/Tenant/Query/QueryEditor/QueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import {
} from '../../../../utils/hooks';
import {useChangedQuerySettings} from '../../../../utils/hooks/useChangedQuerySettings';
import {useLastQueryExecutionSettings} from '../../../../utils/hooks/useLastQueryExecutionSettings';
import {DEFAULT_QUERY_SETTINGS, QUERY_ACTIONS} from '../../../../utils/query';
import {DEFAULT_QUERY_SETTINGS, QUERY_ACTIONS, QUERY_MODES} from '../../../../utils/query';
import type {InitialPaneState} from '../../utils/paneVisibilityToggleHelpers';
import {
PaneVisibilityActionTypes,
Expand Down Expand Up @@ -93,7 +93,11 @@ export default function QueryEditor(props: QueryEditorProps) {
);
const [lastExecutedQueryText, setLastExecutedQueryText] = React.useState<string>('');
const [isQueryStreamingEnabled] = useSetting<boolean>(ENABLE_QUERY_STREAMING);
const isStreamingEnabled = useStreamingAvailable() && isQueryStreamingEnabled;

const isStreamingEnabled =
useStreamingAvailable() &&
isQueryStreamingEnabled &&
querySettings.queryMode === QUERY_MODES.query;

const [sendQuery] = queryApi.useUseSendQueryMutation();
const [streamQuery] = queryApi.useUseStreamQueryMutation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,30 +90,28 @@ export const QueryEditorControls = ({
const [cancelQueryError, setCancelQueryError] = React.useState<boolean>(false);

const onStopButtonClick = React.useCallback(async () => {
if (queryId) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

already have check for sendCancelQuery

try {
if (isStreamingEnabled) {
queryManagerInstance.abortQuery();
} else if (queryId) {
await sendCancelQuery({queryId, database: tenantName}).unwrap();
}
} catch {
createToast({
name: 'stop-error',
title: '',
content: i18n('toaster.stop-error'),
type: 'error',
autoHiding: STOP_AUTO_HIDE_TIMEOUT,
});
setCancelQueryError(true);

if (cancelErrorAnimationRef.current) {
window.clearTimeout(cancelErrorAnimationRef.current);
}
cancelErrorAnimationRef.current = window.setTimeout(() => {
setCancelQueryError(false);
}, CANCEL_ERROR_ANIMATION_DURATION);
try {
if (isStreamingEnabled) {
queryManagerInstance.abortQuery();
} else if (queryId) {
await sendCancelQuery({queryId, database: tenantName}).unwrap();
}
} catch {
createToast({
name: 'stop-error',
title: '',
content: i18n('toaster.stop-error'),
type: 'error',
autoHiding: STOP_AUTO_HIDE_TIMEOUT,
});
setCancelQueryError(true);

if (cancelErrorAnimationRef.current) {
window.clearTimeout(cancelErrorAnimationRef.current);
}
cancelErrorAnimationRef.current = window.setTimeout(() => {
setCancelQueryError(false);
}, CANCEL_ERROR_ANIMATION_DURATION);
}
}, [isStreamingEnabled, queryId, sendCancelQuery, tenantName]);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import React from 'react';

import type {Data} from '@gravity-ui/paranoid';

import {YDBGraph} from '../../../../../../components/Graph/Graph';
import type {PreparedPlan} from '../../../../../../store/reducers/query/types';
import {cn} from '../../../../../../utils/cn';
Expand All @@ -13,18 +17,22 @@ interface GraphProps {
theme?: string;
}

function isValidGraphData(data: Partial<Data>): data is Data {
return Boolean(data.links && data.nodes && data.nodes.length);
}

export function Graph({explain = {}, theme}: GraphProps) {
const {links, nodes} = explain;

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

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

return (
<div className={b('canvas-container')}>
<YDBGraph key={theme} data={{links, nodes}} />
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double useEffect call in YDBGraph that was leading to clearRect error on client (caught in tests)

<YDBGraph key={theme} data={data} />
</div>
);
}
Loading